Upgraded phpseclib to version 0.3.6
This commit is contained in:
parent
4cc70ec39d
commit
3f9beb8c6b
27 changed files with 1287 additions and 723 deletions
|
@ -1,4 +1,4 @@
|
|||
Copyright 2007-2012 TerraFrost and other contributors
|
||||
Copyright 2007-2013 TerraFrost and other contributors
|
||||
http://phpseclib.sourceforge.net/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
|
@ -18,4 +18,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
|
@ -6,11 +6,11 @@ MIT-licensed pure-PHP implementations of an arbitrary-precision integer
|
|||
arithmetic library, fully PKCS#1 (v2.1) compliant RSA, DES, 3DES, RC4, Rijndael,
|
||||
AES, Blowfish, Twofish, SSH-1, SSH-2, SFTP, and X.509
|
||||
|
||||
* [Download (0.3.5)](http://sourceforge.net/projects/phpseclib/files/phpseclib0.3.5.zip/download)
|
||||
* [Download (0.3.6)](http://sourceforge.net/projects/phpseclib/files/phpseclib0.3.6.zip/download)
|
||||
* [Browse Git](https://github.com/phpseclib/phpseclib)
|
||||
* [Documentation](http://phpseclib.sourceforge.net/)
|
||||
* [Support](http://www.frostjedi.com/phpbb/viewforum.php?f=46)
|
||||
* [Code Coverage Report](http://phpseclib.bantux.org/code_coverage/latest/)
|
||||
* [Code Coverage Report](http://phpseclib.bantux.org/code_coverage/master/latest/)
|
||||
|
||||
<img src="http://phpseclib.sourceforge.net/pear-icon.png" alt="PEAR Channel" width="16" height="16">
|
||||
PEAR Channel: [phpseclib.sourceforge.net](http://phpseclib.sourceforge.net/pear.htm)
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
"signing",
|
||||
"rsa",
|
||||
"aes",
|
||||
"blowfish",
|
||||
"twofish",
|
||||
"ssh",
|
||||
"sftp",
|
||||
"x509",
|
||||
|
@ -25,16 +27,34 @@
|
|||
{
|
||||
"name": "Jim Wigginton",
|
||||
"email": "terrafrost@php.net",
|
||||
"role": "Lead Developer"
|
||||
},
|
||||
{
|
||||
"name": "Patrick Monnerat",
|
||||
"email": "pm@datasphere.ch",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Andreas Fischer",
|
||||
"email": "bantu@phpbb.com",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Hans-Jürgen Petrich",
|
||||
"email": "petrich@tronic-media.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"squizlabs/php_codesniffer": "1.*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a wide variety of cryptographic operations.",
|
||||
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
|
||||
"pear-pear/PHP_Compat": "Install PHP_Compat to get phpseclib working on PHP >= 4.3.3."
|
||||
"pear-pear/PHP_Compat": "Install PHP_Compat to get phpseclib working on PHP < 4.3.3."
|
||||
},
|
||||
"include-path": ["phpseclib/"],
|
||||
"autoload": {
|
||||
|
@ -42,7 +62,8 @@
|
|||
"Crypt": "phpseclib/",
|
||||
"File": "phpseclib/",
|
||||
"Math": "phpseclib/",
|
||||
"Net": "phpseclib/"
|
||||
"Net": "phpseclib/",
|
||||
"System": "phpseclib/"
|
||||
},
|
||||
"files": [
|
||||
"phpseclib/Crypt/Random.php"
|
||||
|
|
95
apps/files_external/3rdparty/phpseclib/composer.lock
generated
vendored
Normal file
95
apps/files_external/3rdparty/phpseclib/composer.lock
generated
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||
],
|
||||
"hash": "4975b8cde04a99d6e78e108753845af6",
|
||||
"packages": [
|
||||
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "squizlabs/php_codesniffer",
|
||||
"version": "1.5.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
|
||||
"reference": "a76a39b317ce8106abe6264daa505e24e1731860"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/a76a39b317ce8106abe6264daa505e24e1731860",
|
||||
"reference": "a76a39b317ce8106abe6264daa505e24e1731860",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-tokenizer": "*",
|
||||
"php": ">=5.1.2"
|
||||
},
|
||||
"suggest": {
|
||||
"phpunit/php-timer": "dev-master"
|
||||
},
|
||||
"bin": [
|
||||
"scripts/phpcs"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"CodeSniffer.php",
|
||||
"CodeSniffer/CLI.php",
|
||||
"CodeSniffer/Exception.php",
|
||||
"CodeSniffer/File.php",
|
||||
"CodeSniffer/Report.php",
|
||||
"CodeSniffer/Reporting.php",
|
||||
"CodeSniffer/Sniff.php",
|
||||
"CodeSniffer/Tokens.php",
|
||||
"CodeSniffer/Reports/",
|
||||
"CodeSniffer/CommentParser/",
|
||||
"CodeSniffer/Tokenizers/",
|
||||
"CodeSniffer/DocGenerators/",
|
||||
"CodeSniffer/Standards/AbstractPatternSniff.php",
|
||||
"CodeSniffer/Standards/AbstractScopeSniff.php",
|
||||
"CodeSniffer/Standards/AbstractVariableSniff.php",
|
||||
"CodeSniffer/Standards/IncorrectPatternException.php",
|
||||
"CodeSniffer/Standards/Generic/Sniffs/",
|
||||
"CodeSniffer/Standards/MySource/Sniffs/",
|
||||
"CodeSniffer/Standards/PEAR/Sniffs/",
|
||||
"CodeSniffer/Standards/PSR1/Sniffs/",
|
||||
"CodeSniffer/Standards/PSR2/Sniffs/",
|
||||
"CodeSniffer/Standards/Squiz/Sniffs/",
|
||||
"CodeSniffer/Standards/Zend/Sniffs/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Greg Sherwood",
|
||||
"role": "lead"
|
||||
}
|
||||
],
|
||||
"description": "PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
|
||||
"homepage": "http://www.squizlabs.com/php-codesniffer",
|
||||
"keywords": [
|
||||
"phpcs",
|
||||
"standards"
|
||||
],
|
||||
"time": "2014-02-04 23:49:58"
|
||||
}
|
||||
],
|
||||
"aliases": [
|
||||
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [
|
||||
|
||||
],
|
||||
"platform": {
|
||||
"php": ">=5.0.0"
|
||||
},
|
||||
"platform-dev": [
|
||||
|
||||
]
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of AES.
|
||||
|
@ -54,19 +53,19 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_AES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVIII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_AES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVIII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include Crypt_Rijndael
|
||||
*/
|
||||
if (!class_exists('Crypt_Rijndael')) {
|
||||
require_once('Rijndael.php');
|
||||
include_once 'Rijndael.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -125,12 +124,13 @@ define('CRYPT_AES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
|||
/**
|
||||
* Pure-PHP implementation of AES.
|
||||
*
|
||||
* @package Crypt_AES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Crypt_AES
|
||||
*/
|
||||
class Crypt_AES extends Crypt_Rijndael {
|
||||
class Crypt_AES extends Crypt_Rijndael
|
||||
{
|
||||
/**
|
||||
* The namespace used by the cipher for its constants.
|
||||
*
|
||||
|
@ -183,6 +183,3 @@ class Crypt_AES extends Crypt_Rijndael {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Base Class for all Crypt_* cipher classes
|
||||
|
@ -44,14 +43,14 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_Base
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 1.0.1
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_Base
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 1.0.1
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
|
@ -115,13 +114,14 @@ define('CRYPT_MODE_MCRYPT', 2);
|
|||
/**
|
||||
* Base Class for all Crypt_* cipher classes
|
||||
*
|
||||
* @package Crypt_Base
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @version 1.0.0
|
||||
* @access public
|
||||
* @package Crypt_Base
|
||||
*/
|
||||
class Crypt_Base {
|
||||
class Crypt_Base
|
||||
{
|
||||
/**
|
||||
* The Encryption Mode
|
||||
*
|
||||
|
@ -582,7 +582,7 @@ class Crypt_Base {
|
|||
case !function_exists('hash_algos'):
|
||||
case !in_array($hash, hash_algos()):
|
||||
if (!class_exists('Crypt_Hash')) {
|
||||
require_once('Crypt/Hash.php');
|
||||
include_once 'Crypt/Hash.php';
|
||||
}
|
||||
$i = 1;
|
||||
while (strlen($key) < $dkLen) {
|
||||
|
@ -1984,6 +1984,3 @@ class Crypt_Base {
|
|||
return $functions;
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of Blowfish.
|
||||
|
@ -45,14 +44,14 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_Blowfish
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 1.0
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_Blowfish
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 1.0
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -61,7 +60,7 @@
|
|||
* Base cipher class
|
||||
*/
|
||||
if (!class_exists('Crypt_Base')) {
|
||||
require_once('Base.php');
|
||||
include_once 'Base.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -120,13 +119,14 @@ define('CRYPT_BLOWFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
|||
/**
|
||||
* Pure-PHP implementation of Blowfish.
|
||||
*
|
||||
* @package Crypt_Blowfish
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @version 1.0
|
||||
* @access public
|
||||
* @package Crypt_Blowfish
|
||||
*/
|
||||
class Crypt_Blowfish extends Crypt_Base {
|
||||
class Crypt_Blowfish extends Crypt_Base
|
||||
{
|
||||
/**
|
||||
* Block Length of the cipher
|
||||
*
|
||||
|
@ -418,8 +418,7 @@ class Crypt_Blowfish extends Crypt_Base {
|
|||
|
||||
if (!$keylength) {
|
||||
$key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
}
|
||||
elseif ($keylength > 56) {
|
||||
} elseif ($keylength > 56) {
|
||||
$key = substr($key, 0, 56);
|
||||
}
|
||||
|
||||
|
@ -673,6 +672,3 @@ class Crypt_Blowfish extends Crypt_Base {
|
|||
$this->inline_crypt = $lambda_functions[$code_hash];
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of DES.
|
||||
|
@ -51,12 +50,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_DES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_DES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -65,7 +64,7 @@
|
|||
* Base cipher class
|
||||
*/
|
||||
if (!class_exists('Crypt_Base')) {
|
||||
require_once('Base.php');
|
||||
include_once 'Base.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -139,12 +138,13 @@ define('CRYPT_DES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
|||
/**
|
||||
* Pure-PHP implementation of DES.
|
||||
*
|
||||
* @package Crypt_DES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Crypt_DES
|
||||
*/
|
||||
class Crypt_DES extends Crypt_Base {
|
||||
class Crypt_DES extends Crypt_Base
|
||||
{
|
||||
/**
|
||||
* Block Length of the cipher
|
||||
*
|
||||
|
@ -1336,12 +1336,14 @@ class Crypt_DES extends Crypt_Base {
|
|||
$pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[ $d & 0xFF];
|
||||
|
||||
// Reorder: odd bytes/even bytes. Push the result in key schedule.
|
||||
$keys[$des_round][CRYPT_DES_ENCRYPT][ ] =
|
||||
$keys[$des_round][CRYPT_DES_DECRYPT][$ki - 1] = ( $cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) |
|
||||
(($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF);
|
||||
$keys[$des_round][CRYPT_DES_ENCRYPT][ ] =
|
||||
$keys[$des_round][CRYPT_DES_DECRYPT][$ki ] = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
|
||||
(($dp >> 8) & 0x0000FF00) | ( $dp & 0x000000FF);
|
||||
$val1 = ( $cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) |
|
||||
(($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF);
|
||||
$val2 = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
|
||||
(($dp >> 8) & 0x0000FF00) | ( $dp & 0x000000FF);
|
||||
$keys[$des_round][CRYPT_DES_ENCRYPT][ ] = $val1;
|
||||
$keys[$des_round][CRYPT_DES_DECRYPT][$ki - 1] = $val1;
|
||||
$keys[$des_round][CRYPT_DES_ENCRYPT][ ] = $val2;
|
||||
$keys[$des_round][CRYPT_DES_DECRYPT][$ki ] = $val2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1531,6 +1533,3 @@ class Crypt_DES extends Crypt_Base {
|
|||
$this->inline_crypt = $lambda_functions[$code_hash];
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
|
||||
|
@ -13,7 +12,7 @@
|
|||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* {@internal The variable names are the same as those in
|
||||
* {@internal The variable names are the same as those in
|
||||
* {@link http://tools.ietf.org/html/rfc2104#section-2 RFC2104}.}}
|
||||
*
|
||||
* Here's a short example of how to use this library:
|
||||
|
@ -35,10 +34,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -47,12 +46,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_Hash
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_Hash
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
|
@ -76,12 +75,13 @@ define('CRYPT_HASH_MODE_HASH', 3);
|
|||
/**
|
||||
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
|
||||
*
|
||||
* @package Crypt_Hash
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Crypt_Hash
|
||||
*/
|
||||
class Crypt_Hash {
|
||||
class Crypt_Hash
|
||||
{
|
||||
/**
|
||||
* Hash Parameter
|
||||
*
|
||||
|
@ -581,7 +581,7 @@ class Crypt_Hash {
|
|||
function _sha512($m)
|
||||
{
|
||||
if (!class_exists('Math_BigInteger')) {
|
||||
require_once('Math/BigInteger.php');
|
||||
include_once 'Math/BigInteger.php';
|
||||
}
|
||||
|
||||
static $init384, $init512, $k;
|
||||
|
@ -589,11 +589,11 @@ class Crypt_Hash {
|
|||
if (!isset($k)) {
|
||||
// Initialize variables
|
||||
$init384 = array( // initial values for SHA384
|
||||
'cbbb9d5dc1059ed8', '629a292a367cd507', '9159015a3070dd17', '152fecd8f70e5939',
|
||||
'cbbb9d5dc1059ed8', '629a292a367cd507', '9159015a3070dd17', '152fecd8f70e5939',
|
||||
'67332667ffc00b31', '8eb44a8768581511', 'db0c2e0d64f98fa7', '47b5481dbefa4fa4'
|
||||
);
|
||||
$init512 = array( // initial values for SHA512
|
||||
'6a09e667f3bcc908', 'bb67ae8584caa73b', '3c6ef372fe94f82b', 'a54ff53a5f1d36f1',
|
||||
'6a09e667f3bcc908', 'bb67ae8584caa73b', '3c6ef372fe94f82b', 'a54ff53a5f1d36f1',
|
||||
'510e527fade682d1', '9b05688c2b3e6c1f', '1f83d9abfb41bd6b', '5be0cd19137e2179'
|
||||
);
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of RC2.
|
||||
|
@ -45,11 +44,11 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_RC2
|
||||
* @author Patrick Monnerat <pm@datasphere.ch>
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_RC2
|
||||
* @author Patrick Monnerat <pm@datasphere.ch>
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -58,7 +57,7 @@
|
|||
* Base cipher class
|
||||
*/
|
||||
if (!class_exists('Crypt_Base')) {
|
||||
require_once('Base.php');
|
||||
include_once 'Base.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -117,11 +116,12 @@ define('CRYPT_RC2_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
|||
/**
|
||||
* Pure-PHP implementation of RC2.
|
||||
*
|
||||
* @package Crypt_RC2
|
||||
* @version 0.1.1
|
||||
* @access public
|
||||
* @package Crypt_RC2
|
||||
*/
|
||||
class Crypt_RC2 extends Crypt_Base {
|
||||
class Crypt_RC2 extends Crypt_Base
|
||||
{
|
||||
/**
|
||||
* Block Length of the cipher
|
||||
*
|
||||
|
@ -651,6 +651,3 @@ class Crypt_RC2 extends Crypt_Base {
|
|||
$this->inline_crypt = $lambda_functions[$code_hash];
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of RC4.
|
||||
|
@ -53,12 +52,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_RC4
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_RC4
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -67,7 +66,7 @@
|
|||
* Base cipher class
|
||||
*/
|
||||
if (!class_exists('Crypt_Base')) {
|
||||
require_once('Base.php');
|
||||
include_once 'Base.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -95,20 +94,21 @@ define('CRYPT_RC4_DECRYPT', 1);
|
|||
/**
|
||||
* Pure-PHP implementation of RC4.
|
||||
*
|
||||
* @package Crypt_RC4
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Crypt_RC4
|
||||
*/
|
||||
class Crypt_RC4 extends Crypt_Base {
|
||||
class Crypt_RC4 extends Crypt_Base
|
||||
{
|
||||
/**
|
||||
* Block Length of the cipher
|
||||
*
|
||||
* RC4 is a stream cipher
|
||||
* RC4 is a stream cipher
|
||||
* so we the block_size to 0
|
||||
*
|
||||
* @see Crypt_Base::block_size
|
||||
* @var Integer
|
||||
* @var Integer
|
||||
* @access private
|
||||
*/
|
||||
var $block_size = 0;
|
||||
|
@ -132,7 +132,6 @@ class Crypt_RC4 extends Crypt_Base {
|
|||
*/
|
||||
var $const_namespace = 'RC4';
|
||||
|
||||
|
||||
/**
|
||||
* The mcrypt specific name of the cipher
|
||||
*
|
||||
|
@ -332,6 +331,3 @@ class Crypt_RC4 extends Crypt_Base {
|
|||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP PKCS#1 (v2.1) compliant implementation of RSA.
|
||||
|
@ -48,10 +47,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -60,12 +59,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_RSA
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMIX Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_RSA
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMIX Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -73,17 +72,17 @@
|
|||
*/
|
||||
// the class_exists() will only be called if the crypt_random_string function hasn't been defined and
|
||||
// will trigger a call to __autoload() if you're wanting to auto-load classes
|
||||
// call function_exists() a second time to stop the require_once from being called outside
|
||||
// call function_exists() a second time to stop the include_once from being called outside
|
||||
// of the auto loader
|
||||
if (!function_exists('crypt_random_string')) {
|
||||
require_once('Random.php');
|
||||
include_once 'Random.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Include Crypt_Hash
|
||||
*/
|
||||
if (!class_exists('Crypt_Hash')) {
|
||||
require_once('Hash.php');
|
||||
include_once 'Hash.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -145,7 +144,7 @@ define('CRYPT_RSA_ASN1_INTEGER', 2);
|
|||
/**
|
||||
* ASN1 Bit String
|
||||
*/
|
||||
define('CRYPT_RSA_ASN1_BITSTRING', 3);
|
||||
define('CRYPT_RSA_ASN1_BITSTRING', 3);
|
||||
/**
|
||||
* ASN1 Sequence (with the constucted bit set)
|
||||
*/
|
||||
|
@ -240,12 +239,13 @@ define('CRYPT_RSA_PUBLIC_FORMAT_PKCS1', 7);
|
|||
/**
|
||||
* Pure-PHP PKCS#1 compliant implementation of RSA.
|
||||
*
|
||||
* @package Crypt_RSA
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Crypt_RSA
|
||||
*/
|
||||
class Crypt_RSA {
|
||||
class Crypt_RSA
|
||||
{
|
||||
/**
|
||||
* Precomputed Zero
|
||||
*
|
||||
|
@ -433,7 +433,7 @@ class Crypt_RSA {
|
|||
/**
|
||||
* OpenSSL configuration file name.
|
||||
*
|
||||
* Set to NULL to use system configuration file.
|
||||
* Set to null to use system configuration file.
|
||||
* @see Crypt_RSA::createKey()
|
||||
* @var Mixed
|
||||
* @Access public
|
||||
|
@ -461,7 +461,7 @@ class Crypt_RSA {
|
|||
function Crypt_RSA()
|
||||
{
|
||||
if (!class_exists('Math_BigInteger')) {
|
||||
require_once('Math/BigInteger.php');
|
||||
include_once 'Math/BigInteger.php';
|
||||
}
|
||||
|
||||
$this->configFile = CRYPT_RSA_OPENSSL_CONFIG;
|
||||
|
@ -555,7 +555,7 @@ class Crypt_RSA {
|
|||
$config['config'] = $this->configFile;
|
||||
}
|
||||
$rsa = openssl_pkey_new(array('private_key_bits' => $bits) + $config);
|
||||
openssl_pkey_export($rsa, $privatekey, NULL, $config);
|
||||
openssl_pkey_export($rsa, $privatekey, null, $config);
|
||||
$publickey = openssl_pkey_get_details($rsa);
|
||||
$publickey = $publickey['key'];
|
||||
|
||||
|
@ -773,7 +773,7 @@ class Crypt_RSA {
|
|||
$private.= crypt_random_string(16 - (strlen($private) & 15));
|
||||
$source.= pack('Na*', strlen($private), $private);
|
||||
if (!class_exists('Crypt_AES')) {
|
||||
require_once('Crypt/AES.php');
|
||||
include_once 'Crypt/AES.php';
|
||||
}
|
||||
$sequence = 0;
|
||||
$symkey = '';
|
||||
|
@ -794,7 +794,7 @@ class Crypt_RSA {
|
|||
$key.= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
|
||||
$key.= chunk_split($private, 64);
|
||||
if (!class_exists('Crypt_Hash')) {
|
||||
require_once('Crypt/Hash.php');
|
||||
include_once 'Crypt/Hash.php';
|
||||
}
|
||||
$hash = new Crypt_Hash('sha1');
|
||||
$hash->setKey(pack('H*', sha1($hashkey)));
|
||||
|
@ -834,7 +834,7 @@ class Crypt_RSA {
|
|||
$symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key
|
||||
$symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$des = new Crypt_TripleDES();
|
||||
$des->setKey($symkey);
|
||||
|
@ -984,7 +984,7 @@ class Crypt_RSA {
|
|||
DES-EDE3-CBC as an algorithm, however, is not discussed anywhere, near as I can tell.
|
||||
DES-CBC and DES-EDE are discussed in RFC1423, however, DES-EDE3-CBC isn't, nor is its key derivation
|
||||
function. As is, the definitive authority on this encoding scheme isn't the IETF but rather OpenSSL's
|
||||
own implementation. ie. the implementation *is* the standard and any bugs that may exist in that
|
||||
own implementation. ie. the implementation *is* the standard and any bugs that may exist in that
|
||||
implementation are part of the standard, as well.
|
||||
|
||||
* OpenSSL is the de facto standard. It's utilized by OpenSSH and other projects */
|
||||
|
@ -992,41 +992,42 @@ class Crypt_RSA {
|
|||
$iv = pack('H*', trim($matches[2]));
|
||||
$symkey = pack('H*', md5($this->password . substr($iv, 0, 8))); // symkey is short for symmetric key
|
||||
$symkey.= pack('H*', md5($symkey . $this->password . substr($iv, 0, 8)));
|
||||
$ciphertext = preg_replace('#.+(\r|\n|\r\n)\1|[\r\n]|-.+-| #s', '', $key);
|
||||
$ciphertext = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $ciphertext) ? base64_decode($ciphertext) : false;
|
||||
// remove the Proc-Type / DEK-Info sections as they're no longer needed
|
||||
$key = preg_replace('#^(?:Proc-Type|DEK-Info): .*#m', '', $key);
|
||||
$ciphertext = $this->_extractBER($key);
|
||||
if ($ciphertext === false) {
|
||||
$ciphertext = $key;
|
||||
}
|
||||
switch ($matches[1]) {
|
||||
case 'AES-256-CBC':
|
||||
if (!class_exists('Crypt_AES')) {
|
||||
require_once('Crypt/AES.php');
|
||||
include_once 'Crypt/AES.php';
|
||||
}
|
||||
$crypto = new Crypt_AES();
|
||||
break;
|
||||
case 'AES-128-CBC':
|
||||
if (!class_exists('Crypt_AES')) {
|
||||
require_once('Crypt/AES.php');
|
||||
include_once 'Crypt/AES.php';
|
||||
}
|
||||
$symkey = substr($symkey, 0, 16);
|
||||
$crypto = new Crypt_AES();
|
||||
break;
|
||||
case 'DES-EDE3-CFB':
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
|
||||
break;
|
||||
case 'DES-EDE3-CBC':
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$symkey = substr($symkey, 0, 24);
|
||||
$crypto = new Crypt_TripleDES();
|
||||
break;
|
||||
case 'DES-CBC':
|
||||
if (!class_exists('Crypt_DES')) {
|
||||
require_once('Crypt/DES.php');
|
||||
include_once 'Crypt/DES.php';
|
||||
}
|
||||
$crypto = new Crypt_DES();
|
||||
break;
|
||||
|
@ -1037,8 +1038,7 @@ class Crypt_RSA {
|
|||
$crypto->setIV($iv);
|
||||
$decoded = $crypto->decrypt($ciphertext);
|
||||
} else {
|
||||
$decoded = preg_replace('#-.+-|[\r\n]| #', '', $key);
|
||||
$decoded = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $decoded) ? base64_decode($decoded) : false;
|
||||
$decoded = $this->_extractBER($key);
|
||||
}
|
||||
|
||||
if ($decoded !== false) {
|
||||
|
@ -1240,7 +1240,7 @@ class Crypt_RSA {
|
|||
switch ($encryption) {
|
||||
case 'aes256-cbc':
|
||||
if (!class_exists('Crypt_AES')) {
|
||||
require_once('Crypt/AES.php');
|
||||
include_once 'Crypt/AES.php';
|
||||
}
|
||||
$symkey = '';
|
||||
$sequence = 0;
|
||||
|
@ -1452,7 +1452,7 @@ class Crypt_RSA {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
$components = $this->_parseKey($key, $type);
|
||||
}
|
||||
|
@ -2152,7 +2152,7 @@ class Crypt_RSA {
|
|||
*
|
||||
* See {@link http://tools.ietf.org/html/rfc3447#section-7.1.2 RFC3447#section-7.1.2}. The fact that the error
|
||||
* messages aren't distinguishable from one another hinders debugging, but, to quote from RFC3447#section-7.1.2:
|
||||
*
|
||||
*
|
||||
* Note. Care must be taken to ensure that an opponent cannot
|
||||
* distinguish the different error conditions in Step 3.g, whether by
|
||||
* error message or timing, or, more generally, learn partial
|
||||
|
@ -2781,4 +2781,31 @@ class Crypt_RSA {
|
|||
return $this->_rsassa_pss_verify($message, $signature);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract raw BER from Base64 encoding
|
||||
*
|
||||
* @access private
|
||||
* @param String $str
|
||||
* @return String
|
||||
*/
|
||||
function _extractBER($str)
|
||||
{
|
||||
/* X.509 certs are assumed to be base64 encoded but sometimes they'll have additional things in them
|
||||
* above and beyond the ceritificate.
|
||||
* ie. some may have the following preceding the -----BEGIN CERTIFICATE----- line:
|
||||
*
|
||||
* Bag Attributes
|
||||
* localKeyID: 01 00 00 00
|
||||
* subject=/O=organization/OU=org unit/CN=common name
|
||||
* issuer=/O=organization/CN=common name
|
||||
*/
|
||||
$temp = preg_replace('#.*?^-+[^-]+-+#ms', '', $str, 1);
|
||||
// remove the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- stuff
|
||||
$temp = preg_replace('#-+[^-]+-+#', '', $temp);
|
||||
// remove new lines
|
||||
$temp = str_replace(array("\r", "\n", ' '), '', $temp);
|
||||
$temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false;
|
||||
return $temp != false ? $temp : $str;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Random Number Generator
|
||||
|
@ -33,12 +32,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_Random
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_Random
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -132,9 +131,7 @@ function crypt_random_string($length)
|
|||
$old_session_id = session_id();
|
||||
$old_use_cookies = ini_get('session.use_cookies');
|
||||
$old_session_cache_limiter = session_cache_limiter();
|
||||
if (isset($_SESSION)) {
|
||||
$_OLD_SESSION = $_SESSION;
|
||||
}
|
||||
$_OLD_SESSION = isset($_SESSION) ? $_SESSION : false;
|
||||
if ($old_session_id != '') {
|
||||
session_write_close();
|
||||
}
|
||||
|
@ -167,7 +164,7 @@ function crypt_random_string($length)
|
|||
ini_set('session.use_cookies', $old_use_cookies);
|
||||
session_cache_limiter($old_session_cache_limiter);
|
||||
} else {
|
||||
if (isset($_OLD_SESSION)) {
|
||||
if ($_OLD_SESSION !== false) {
|
||||
$_SESSION = $_OLD_SESSION;
|
||||
unset($_OLD_SESSION);
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of Rijndael.
|
||||
|
@ -63,12 +62,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_Rijndael
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVIII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_Rijndael
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVIII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -77,7 +76,7 @@
|
|||
* Base cipher class
|
||||
*/
|
||||
if (!class_exists('Crypt_Base')) {
|
||||
require_once('Base.php');
|
||||
include_once 'Base.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -136,12 +135,13 @@ define('CRYPT_RIJNDAEL_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
|||
/**
|
||||
* Pure-PHP implementation of Rijndael.
|
||||
*
|
||||
* @package Crypt_Rijndael
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Crypt_Rijndael
|
||||
*/
|
||||
class Crypt_Rijndael extends Crypt_Base {
|
||||
class Crypt_Rijndael extends Crypt_Base
|
||||
{
|
||||
/**
|
||||
* The default password key_size used by setPassword()
|
||||
*
|
||||
|
@ -1369,6 +1369,3 @@ class Crypt_Rijndael extends Crypt_Base {
|
|||
$this->inline_crypt = $lambda_functions[$code_hash];
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of Triple DES.
|
||||
|
@ -45,19 +44,19 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_TripleDES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_TripleDES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include Crypt_DES
|
||||
*/
|
||||
if (!class_exists('Crypt_DES')) {
|
||||
require_once('DES.php');
|
||||
include_once 'DES.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,12 +76,13 @@ define('CRYPT_DES_MODE_CBC3', CRYPT_DES_MODE_CBC);
|
|||
/**
|
||||
* Pure-PHP implementation of Triple DES.
|
||||
*
|
||||
* @package Crypt_TripleDES
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Crypt_TripleDES
|
||||
*/
|
||||
class Crypt_TripleDES extends Crypt_DES {
|
||||
class Crypt_TripleDES extends Crypt_DES
|
||||
{
|
||||
/**
|
||||
* The default password key_size used by setPassword()
|
||||
*
|
||||
|
@ -417,6 +417,3 @@ class Crypt_TripleDES extends Crypt_DES {
|
|||
parent::_setupKey();
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of Twofish.
|
||||
|
@ -45,14 +44,14 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package Crypt_Twofish
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 1.0
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Crypt
|
||||
* @package Crypt_Twofish
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 1.0
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -61,7 +60,7 @@
|
|||
* Base cipher class
|
||||
*/
|
||||
if (!class_exists('Crypt_Base')) {
|
||||
require_once('Base.php');
|
||||
include_once 'Base.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -120,13 +119,14 @@ define('CRYPT_TWOFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
|||
/**
|
||||
* Pure-PHP implementation of Twofish.
|
||||
*
|
||||
* @package Crypt_Twofish
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @version 1.0
|
||||
* @access public
|
||||
* @package Crypt_Twofish
|
||||
*/
|
||||
class Crypt_Twofish extends Crypt_Base {
|
||||
class Crypt_Twofish extends Crypt_Base
|
||||
{
|
||||
/**
|
||||
* The namespace used by the cipher for its constants.
|
||||
*
|
||||
|
@ -919,6 +919,3 @@ class Crypt_Twofish extends Crypt_Base {
|
|||
$this->inline_crypt = $lambda_functions[$code_hash];
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP ANSI Decoder
|
||||
|
@ -17,10 +16,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -29,23 +28,24 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category File
|
||||
* @package File_ANSI
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category File
|
||||
* @package File_ANSI
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pure-PHP ANSI Decoder
|
||||
*
|
||||
* @package File_ANSI
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.3.0
|
||||
* @access public
|
||||
* @package File_ANSI
|
||||
*/
|
||||
class File_ANSI {
|
||||
class File_ANSI
|
||||
{
|
||||
/**
|
||||
* Max Width
|
||||
*
|
||||
|
@ -557,4 +557,4 @@ class File_ANSI {
|
|||
|
||||
return '<pre style="color: white; background: black" width="' . ($this->max_x + 1) . '">' . $scrollback . '</pre>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP ASN.1 Parser
|
||||
|
@ -20,10 +19,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -32,12 +31,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category File
|
||||
* @package File_ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category File
|
||||
* @package File_ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
|
@ -58,21 +57,21 @@ define('FILE_ASN1_CLASS_PRIVATE', 3);
|
|||
* @access private
|
||||
* @link http://www.obj-sys.com/asn1tutorial/node124.html
|
||||
*/
|
||||
define('FILE_ASN1_TYPE_BOOLEAN', 1);
|
||||
define('FILE_ASN1_TYPE_INTEGER', 2);
|
||||
define('FILE_ASN1_TYPE_BIT_STRING', 3);
|
||||
define('FILE_ASN1_TYPE_OCTET_STRING', 4);
|
||||
define('FILE_ASN1_TYPE_NULL', 5);
|
||||
define('FILE_ASN1_TYPE_OBJECT_IDENTIFIER',6);
|
||||
//define('FILE_ASN1_TYPE_OBJECT_DESCRIPTOR',7);
|
||||
//define('FILE_ASN1_TYPE_INSTANCE_OF', 8); // EXTERNAL
|
||||
define('FILE_ASN1_TYPE_REAL', 9);
|
||||
define('FILE_ASN1_TYPE_ENUMERATED', 10);
|
||||
//define('FILE_ASN1_TYPE_EMBEDDED', 11);
|
||||
define('FILE_ASN1_TYPE_UTF8_STRING', 12);
|
||||
//define('FILE_ASN1_TYPE_RELATIVE_OID', 13);
|
||||
define('FILE_ASN1_TYPE_SEQUENCE', 16); // SEQUENCE OF
|
||||
define('FILE_ASN1_TYPE_SET', 17); // SET OF
|
||||
define('FILE_ASN1_TYPE_BOOLEAN', 1);
|
||||
define('FILE_ASN1_TYPE_INTEGER', 2);
|
||||
define('FILE_ASN1_TYPE_BIT_STRING', 3);
|
||||
define('FILE_ASN1_TYPE_OCTET_STRING', 4);
|
||||
define('FILE_ASN1_TYPE_NULL', 5);
|
||||
define('FILE_ASN1_TYPE_OBJECT_IDENTIFIER', 6);
|
||||
//define('FILE_ASN1_TYPE_OBJECT_DESCRIPTOR', 7);
|
||||
//define('FILE_ASN1_TYPE_INSTANCE_OF', 8); // EXTERNAL
|
||||
define('FILE_ASN1_TYPE_REAL', 9);
|
||||
define('FILE_ASN1_TYPE_ENUMERATED', 10);
|
||||
//define('FILE_ASN1_TYPE_EMBEDDED', 11);
|
||||
define('FILE_ASN1_TYPE_UTF8_STRING', 12);
|
||||
//define('FILE_ASN1_TYPE_RELATIVE_OID', 13);
|
||||
define('FILE_ASN1_TYPE_SEQUENCE', 16); // SEQUENCE OF
|
||||
define('FILE_ASN1_TYPE_SET', 17); // SET OF
|
||||
/**#@-*/
|
||||
/**#@+
|
||||
* More Tag Classes
|
||||
|
@ -80,19 +79,19 @@ define('FILE_ASN1_TYPE_SET', 17); // SET OF
|
|||
* @access private
|
||||
* @link http://www.obj-sys.com/asn1tutorial/node10.html
|
||||
*/
|
||||
define('FILE_ASN1_TYPE_NUMERIC_STRING', 18);
|
||||
define('FILE_ASN1_TYPE_PRINTABLE_STRING',19);
|
||||
define('FILE_ASN1_TYPE_TELETEX_STRING', 20); // T61String
|
||||
define('FILE_ASN1_TYPE_VIDEOTEX_STRING', 21);
|
||||
define('FILE_ASN1_TYPE_IA5_STRING', 22);
|
||||
define('FILE_ASN1_TYPE_UTC_TIME', 23);
|
||||
define('FILE_ASN1_TYPE_GENERALIZED_TIME',24);
|
||||
define('FILE_ASN1_TYPE_GRAPHIC_STRING', 25);
|
||||
define('FILE_ASN1_TYPE_VISIBLE_STRING', 26); // ISO646String
|
||||
define('FILE_ASN1_TYPE_GENERAL_STRING', 27);
|
||||
define('FILE_ASN1_TYPE_UNIVERSAL_STRING',28);
|
||||
//define('FILE_ASN1_TYPE_CHARACTER_STRING',29);
|
||||
define('FILE_ASN1_TYPE_BMP_STRING', 30);
|
||||
define('FILE_ASN1_TYPE_NUMERIC_STRING', 18);
|
||||
define('FILE_ASN1_TYPE_PRINTABLE_STRING', 19);
|
||||
define('FILE_ASN1_TYPE_TELETEX_STRING', 20); // T61String
|
||||
define('FILE_ASN1_TYPE_VIDEOTEX_STRING', 21);
|
||||
define('FILE_ASN1_TYPE_IA5_STRING', 22);
|
||||
define('FILE_ASN1_TYPE_UTC_TIME', 23);
|
||||
define('FILE_ASN1_TYPE_GENERALIZED_TIME', 24);
|
||||
define('FILE_ASN1_TYPE_GRAPHIC_STRING', 25);
|
||||
define('FILE_ASN1_TYPE_VISIBLE_STRING', 26); // ISO646String
|
||||
define('FILE_ASN1_TYPE_GENERAL_STRING', 27);
|
||||
define('FILE_ASN1_TYPE_UNIVERSAL_STRING', 28);
|
||||
//define('FILE_ASN1_TYPE_CHARACTER_STRING', 29);
|
||||
define('FILE_ASN1_TYPE_BMP_STRING', 30);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
|
@ -111,12 +110,13 @@ define('FILE_ASN1_TYPE_ANY', -2);
|
|||
*
|
||||
* Bypass normal encoding rules in File_ASN1::encodeDER()
|
||||
*
|
||||
* @package File_ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.3.0
|
||||
* @access public
|
||||
* @package File_ASN1
|
||||
*/
|
||||
class File_ASN1_Element {
|
||||
class File_ASN1_Element
|
||||
{
|
||||
/**
|
||||
* Raw element value
|
||||
*
|
||||
|
@ -141,12 +141,13 @@ class File_ASN1_Element {
|
|||
/**
|
||||
* Pure-PHP ASN.1 Parser
|
||||
*
|
||||
* @package File_ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.3.0
|
||||
* @access public
|
||||
* @package File_ASN1
|
||||
*/
|
||||
class File_ASN1 {
|
||||
class File_ASN1
|
||||
{
|
||||
/**
|
||||
* ASN.1 object identifier
|
||||
*
|
||||
|
@ -252,7 +253,7 @@ class File_ASN1 {
|
|||
if (!$static_init) {
|
||||
$static_init = true;
|
||||
if (!class_exists('Math_BigInteger')) {
|
||||
require_once('Math/BigInteger.php');
|
||||
include_once 'Math/BigInteger.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +317,7 @@ class File_ASN1 {
|
|||
$length = ord($this->_string_shift($encoded));
|
||||
$start++;
|
||||
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
|
||||
//if ( !$constructed ) {
|
||||
// return false;
|
||||
|
@ -419,7 +420,7 @@ class File_ASN1 {
|
|||
//}
|
||||
$current['content'].= $temp[$i]['content'];
|
||||
}
|
||||
// $length =
|
||||
// $length =
|
||||
}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_NULL:
|
||||
|
@ -456,7 +457,7 @@ class File_ASN1 {
|
|||
|
||||
-- X.690-0207.pdf#page=23 (paragraph 8.21.3)
|
||||
|
||||
Per that, we're not going to do any validation. If there are any illegal characters in the string,
|
||||
Per that, we're not going to do any validation. If there are any illegal characters in the string,
|
||||
we don't really care */
|
||||
case FILE_ASN1_TYPE_NUMERIC_STRING:
|
||||
// 0,1,2,3,4,5,6,7,8,9, and space
|
||||
|
@ -545,13 +546,13 @@ class File_ASN1 {
|
|||
return array($key => $value);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return null;
|
||||
case isset($mapping['implicit']):
|
||||
case isset($mapping['explicit']):
|
||||
case $decoded['type'] == $mapping['type']:
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($mapping['implicit'])) {
|
||||
|
@ -566,8 +567,8 @@ class File_ASN1 {
|
|||
if (isset($mapping['min']) && isset($mapping['max'])) {
|
||||
$child = $mapping['children'];
|
||||
foreach ($decoded['content'] as $content) {
|
||||
if (($map[] = $this->asn1map($content, $child, $special)) === NULL) {
|
||||
return NULL;
|
||||
if (($map[] = $this->asn1map($content, $child, $special)) === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -585,15 +586,14 @@ class File_ASN1 {
|
|||
if ($child['type'] != FILE_ASN1_TYPE_CHOICE) {
|
||||
// Get the mapping and input class & constant.
|
||||
$childClass = $tempClass = FILE_ASN1_CLASS_UNIVERSAL;
|
||||
$constant = NULL;
|
||||
$constant = null;
|
||||
if (isset($temp['constant'])) {
|
||||
$tempClass = isset($temp['class']) ? $temp['class'] : FILE_ASN1_CLASS_CONTEXT_SPECIFIC;
|
||||
}
|
||||
if (isset($child['class'])) {
|
||||
$childClass = $child['class'];
|
||||
$constant = $child['cast'];
|
||||
}
|
||||
elseif (isset($child['constant'])) {
|
||||
} elseif (isset($child['constant'])) {
|
||||
$childClass = FILE_ASN1_CLASS_CONTEXT_SPECIFIC;
|
||||
$constant = $child['constant'];
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ class File_ASN1 {
|
|||
if ($maymatch) {
|
||||
// Attempt submapping.
|
||||
$candidate = $this->asn1map($temp, $child, $special);
|
||||
$maymatch = $candidate !== NULL;
|
||||
$maymatch = $candidate !== null;
|
||||
}
|
||||
|
||||
if ($maymatch) {
|
||||
|
@ -624,12 +624,12 @@ class File_ASN1 {
|
|||
} elseif (isset($child['default'])) {
|
||||
$map[$key] = $child['default']; // Use default.
|
||||
} elseif (!isset($child['optional'])) {
|
||||
return NULL; // Syntax error.
|
||||
return null; // Syntax error.
|
||||
}
|
||||
}
|
||||
|
||||
// Fail mapping if all input items have not been consumed.
|
||||
return $i < $n? NULL: $map;
|
||||
return $i < $n? null: $map;
|
||||
|
||||
// the main diff between sets and sequences is the encapsulation of the foreach in another for loop
|
||||
case FILE_ASN1_TYPE_SET:
|
||||
|
@ -639,8 +639,8 @@ class File_ASN1 {
|
|||
if (isset($mapping['min']) && isset($mapping['max'])) {
|
||||
$child = $mapping['children'];
|
||||
foreach ($decoded['content'] as $content) {
|
||||
if (($map[] = $this->asn1map($content, $child, $special)) === NULL) {
|
||||
return NULL;
|
||||
if (($map[] = $this->asn1map($content, $child, $special)) === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -661,12 +661,11 @@ class File_ASN1 {
|
|||
$maymatch = true;
|
||||
if ($child['type'] != FILE_ASN1_TYPE_CHOICE) {
|
||||
$childClass = FILE_ASN1_CLASS_UNIVERSAL;
|
||||
$constant = NULL;
|
||||
$constant = null;
|
||||
if (isset($child['class'])) {
|
||||
$childClass = $child['class'];
|
||||
$constant = $child['cast'];
|
||||
}
|
||||
elseif (isset($child['constant'])) {
|
||||
} elseif (isset($child['constant'])) {
|
||||
$childClass = FILE_ASN1_CLASS_CONTEXT_SPECIFIC;
|
||||
$constant = $child['constant'];
|
||||
}
|
||||
|
@ -683,7 +682,7 @@ class File_ASN1 {
|
|||
if ($maymatch) {
|
||||
// Attempt submapping.
|
||||
$candidate = $this->asn1map($temp, $child, $special);
|
||||
$maymatch = $candidate !== NULL;
|
||||
$maymatch = $candidate !== null;
|
||||
}
|
||||
|
||||
if (!$maymatch) {
|
||||
|
@ -704,7 +703,7 @@ class File_ASN1 {
|
|||
if (isset($child['default'])) {
|
||||
$map[$key] = $child['default'];
|
||||
} elseif (!isset($child['optional'])) {
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -797,7 +796,7 @@ class File_ASN1 {
|
|||
function encodeDER($source, $mapping, $special = array())
|
||||
{
|
||||
$this->location = array();
|
||||
return $this->_encode_der($source, $mapping, NULL, $special);
|
||||
return $this->_encode_der($source, $mapping, null, $special);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -819,7 +818,7 @@ class File_ASN1 {
|
|||
* @return String
|
||||
* @access private
|
||||
*/
|
||||
function _encode_der($source, $mapping, $idx = NULL, $special = array())
|
||||
function _encode_der($source, $mapping, $idx = null, $special = array())
|
||||
{
|
||||
if (is_object($source) && strtolower(get_class($source)) == 'file_asn1_element') {
|
||||
return $source->element;
|
||||
|
@ -850,7 +849,7 @@ class File_ASN1 {
|
|||
$child = $mapping['children'];
|
||||
|
||||
foreach ($source as $content) {
|
||||
$temp = $this->_encode_der($content, $child, NULL, $special);
|
||||
$temp = $this->_encode_der($content, $child, null, $special);
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1030,19 +1029,19 @@ class File_ASN1 {
|
|||
|
||||
switch (true) {
|
||||
case !isset($source):
|
||||
return $this->_encode_der(NULL, array('type' => FILE_ASN1_TYPE_NULL) + $mapping, NULL, $special);
|
||||
return $this->_encode_der(null, array('type' => FILE_ASN1_TYPE_NULL) + $mapping, null, $special);
|
||||
case is_int($source):
|
||||
case is_object($source) && strtolower(get_class($source)) == 'math_biginteger':
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_INTEGER) + $mapping, NULL, $special);
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_INTEGER) + $mapping, null, $special);
|
||||
case is_float($source):
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_REAL) + $mapping, NULL, $special);
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_REAL) + $mapping, null, $special);
|
||||
case is_bool($source):
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_BOOLEAN) + $mapping, NULL, $special);
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_BOOLEAN) + $mapping, null, $special);
|
||||
case is_array($source) && count($source) == 1:
|
||||
$typename = implode('', array_keys($source));
|
||||
$outtype = array_search($typename, $this->ANYmap, true);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1058,7 +1057,7 @@ class File_ASN1 {
|
|||
user_error('No filters defined for ' . implode('/', $loc));
|
||||
return false;
|
||||
}
|
||||
return $this->_encode_der($source, $filters + $mapping, NULL, $special);
|
||||
return $this->_encode_der($source, $filters + $mapping, null, $special);
|
||||
case FILE_ASN1_TYPE_NULL:
|
||||
$value = '';
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP X.509 Parser
|
||||
|
@ -8,7 +7,7 @@
|
|||
*
|
||||
* Encode and decode X.509 certificates.
|
||||
*
|
||||
* The extensions are from {@link http://tools.ietf.org/html/rfc5280 RFC5280} and
|
||||
* The extensions are from {@link http://tools.ietf.org/html/rfc5280 RFC5280} and
|
||||
* {@link http://web.archive.org/web/19961027104704/http://www3.netscape.com/eng/security/cert-exts.html Netscape Certificate Extensions}.
|
||||
*
|
||||
* Note that loading an X.509 certificate and resaving it may invalidate the signature. The reason being that the signature is based on a
|
||||
|
@ -23,10 +22,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -35,19 +34,19 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category File
|
||||
* @package File_X509
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category File
|
||||
* @package File_X509
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include File_ASN1
|
||||
*/
|
||||
if (!class_exists('File_ASN1')) {
|
||||
require_once('ASN1.php');
|
||||
include_once 'ASN1.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,12 +123,13 @@ define('FILE_X509_ATTR_REPLACE', -3); // Clear first, then add a value.
|
|||
/**
|
||||
* Pure-PHP X.509 Parser
|
||||
*
|
||||
* @package File_X509
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.3.1
|
||||
* @access public
|
||||
* @package File_X509
|
||||
*/
|
||||
class File_X509 {
|
||||
class File_X509
|
||||
{
|
||||
/**
|
||||
* ASN.1 syntax for X.509 certificates
|
||||
*
|
||||
|
@ -248,7 +248,7 @@ class File_X509 {
|
|||
* The signature subject
|
||||
*
|
||||
* There's no guarantee File_X509 is going to reencode an X.509 cert in the same way it was originally
|
||||
* encoded so we take save the portion of the original cert that the signature would have made for.
|
||||
* encoded so we take save the portion of the original cert that the signature would have made for.
|
||||
*
|
||||
* @var String
|
||||
* @access private
|
||||
|
@ -307,7 +307,7 @@ class File_X509 {
|
|||
function File_X509()
|
||||
{
|
||||
if (!class_exists('Math_BigInteger')) {
|
||||
require_once('Math/BigInteger.php');
|
||||
include_once 'Math/BigInteger.php';
|
||||
}
|
||||
|
||||
// Explicitly Tagged Module, 1988 Syntax
|
||||
|
@ -1431,7 +1431,7 @@ class File_X509 {
|
|||
$this->currentCert = $cert;
|
||||
|
||||
$currentKeyIdentifier = $this->getExtension('id-ce-subjectKeyIdentifier');
|
||||
$this->currentKeyIdentifier = is_string($currentKeyIdentifier) ? $currentKeyIdentifier : NULL;
|
||||
$this->currentKeyIdentifier = is_string($currentKeyIdentifier) ? $currentKeyIdentifier : null;
|
||||
|
||||
unset($this->signatureSubject);
|
||||
|
||||
|
@ -1469,7 +1469,7 @@ class File_X509 {
|
|||
$this->dn = $x509['tbsCertificate']['subject'];
|
||||
|
||||
$currentKeyIdentifier = $this->getExtension('id-ce-subjectKeyIdentifier');
|
||||
$this->currentKeyIdentifier = is_string($currentKeyIdentifier) ? $currentKeyIdentifier : NULL;
|
||||
$this->currentKeyIdentifier = is_string($currentKeyIdentifier) ? $currentKeyIdentifier : null;
|
||||
|
||||
return $x509;
|
||||
}
|
||||
|
@ -1496,33 +1496,33 @@ class File_X509 {
|
|||
default:
|
||||
switch ($algorithm) {
|
||||
case 'rsaEncryption':
|
||||
$cert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'] =
|
||||
base64_encode("\0" . base64_decode(preg_replace('#-.+-|[\r\n]#', '', $cert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'])));
|
||||
$cert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey']
|
||||
= base64_encode("\0" . base64_decode(preg_replace('#-.+-|[\r\n]#', '', $cert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'])));
|
||||
}
|
||||
}
|
||||
|
||||
$asn1 = new File_ASN1();
|
||||
|
||||
$asn1->loadOIDs($this->oids);
|
||||
|
||||
$filters = array();
|
||||
$filters['tbsCertificate']['signature']['parameters'] =
|
||||
$filters['tbsCertificate']['signature']['issuer']['rdnSequence']['value'] =
|
||||
$filters['tbsCertificate']['issuer']['rdnSequence']['value'] =
|
||||
$filters['tbsCertificate']['subject']['rdnSequence']['value'] =
|
||||
$filters['tbsCertificate']['subjectPublicKeyInfo']['algorithm']['parameters'] =
|
||||
$filters['signatureAlgorithm']['parameters'] =
|
||||
$filters['authorityCertIssuer']['directoryName']['rdnSequence']['value'] =
|
||||
//$filters['policyQualifiers']['qualifier'] =
|
||||
$filters['distributionPoint']['fullName']['directoryName']['rdnSequence']['value'] =
|
||||
$filters['directoryName']['rdnSequence']['value'] =
|
||||
array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
$type_utf8_string = array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
$filters['tbsCertificate']['signature']['parameters'] = $type_utf8_string;
|
||||
$filters['tbsCertificate']['signature']['issuer']['rdnSequence']['value'] = $type_utf8_string;
|
||||
$filters['tbsCertificate']['issuer']['rdnSequence']['value'] = $type_utf8_string;
|
||||
$filters['tbsCertificate']['subject']['rdnSequence']['value'] = $type_utf8_string;
|
||||
$filters['tbsCertificate']['subjectPublicKeyInfo']['algorithm']['parameters'] = $type_utf8_string;
|
||||
$filters['signatureAlgorithm']['parameters'] = $type_utf8_string;
|
||||
$filters['authorityCertIssuer']['directoryName']['rdnSequence']['value'] = $type_utf8_string;
|
||||
//$filters['policyQualifiers']['qualifier'] = $type_utf8_string;
|
||||
$filters['distributionPoint']['fullName']['directoryName']['rdnSequence']['value'] = $type_utf8_string;
|
||||
$filters['directoryName']['rdnSequence']['value'] = $type_utf8_string;
|
||||
|
||||
/* in the case of policyQualifiers/qualifier, the type has to be FILE_ASN1_TYPE_IA5_STRING.
|
||||
FILE_ASN1_TYPE_PRINTABLE_STRING will cause OpenSSL's X.509 parser to spit out random
|
||||
characters.
|
||||
*/
|
||||
$filters['policyQualifiers']['qualifier'] =
|
||||
array('type' => FILE_ASN1_TYPE_IA5_STRING);
|
||||
$filters['policyQualifiers']['qualifier']
|
||||
= array('type' => FILE_ASN1_TYPE_IA5_STRING);
|
||||
|
||||
$asn1->loadFilters($filters);
|
||||
|
||||
|
@ -1715,8 +1715,7 @@ class File_X509 {
|
|||
if ($map === false) {
|
||||
user_error($id . ' is not a currently supported attribute', E_USER_NOTICE);
|
||||
unset($attributes[$i]);
|
||||
}
|
||||
elseif (is_array($attributes[$i]['value'])) {
|
||||
} elseif (is_array($attributes[$i]['value'])) {
|
||||
$values = &$attributes[$i]['value'];
|
||||
for ($j = 0; $j < count($values); $j++) {
|
||||
switch ($id) {
|
||||
|
@ -1963,7 +1962,7 @@ class File_X509 {
|
|||
* @param Integer $date optional
|
||||
* @access public
|
||||
*/
|
||||
function validateDate($date = NULL)
|
||||
function validateDate($date = null)
|
||||
{
|
||||
if (!is_array($this->currentCert) || !isset($this->currentCert['tbsCertificate'])) {
|
||||
return false;
|
||||
|
@ -1992,7 +1991,7 @@ class File_X509 {
|
|||
* Validate a signature
|
||||
*
|
||||
* Works on X.509 certs, CSR's and CRL's.
|
||||
* Returns true if the signature is verified, false if it is not correct or NULL on error
|
||||
* Returns true if the signature is verified, false if it is not correct or null on error
|
||||
*
|
||||
* By default returns false for self-signed certs. Call validateSignature(false) to make this support
|
||||
* self-signed.
|
||||
|
@ -2006,7 +2005,7 @@ class File_X509 {
|
|||
function validateSignature($caonly = true)
|
||||
{
|
||||
if (!is_array($this->currentCert) || !isset($this->signatureSubject)) {
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
|
||||
/* TODO:
|
||||
|
@ -2107,7 +2106,7 @@ class File_X509 {
|
|||
/**
|
||||
* Validates a signature
|
||||
*
|
||||
* Returns true if the signature is verified, false if it is not correct or NULL on error
|
||||
* Returns true if the signature is verified, false if it is not correct or null on error
|
||||
*
|
||||
* @param String $publicKeyAlgorithm
|
||||
* @param String $publicKey
|
||||
|
@ -2122,7 +2121,7 @@ class File_X509 {
|
|||
switch ($publicKeyAlgorithm) {
|
||||
case 'rsaEncryption':
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
require_once('Crypt/RSA.php');
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
$rsa = new Crypt_RSA();
|
||||
$rsa->loadKey($publicKey);
|
||||
|
@ -2142,11 +2141,11 @@ class File_X509 {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -2367,7 +2366,7 @@ class File_X509 {
|
|||
* @return Mixed
|
||||
* @access public
|
||||
*/
|
||||
function getDNProp($propName, $dn = NULL, $withType = false)
|
||||
function getDNProp($propName, $dn = null, $withType = false)
|
||||
{
|
||||
if (!isset($dn)) {
|
||||
$dn = $this->dn;
|
||||
|
@ -2421,7 +2420,7 @@ class File_X509 {
|
|||
function setDN($dn, $merge = false, $type = 'utf8String')
|
||||
{
|
||||
if (!$merge) {
|
||||
$this->dn = NULL;
|
||||
$this->dn = null;
|
||||
}
|
||||
|
||||
if (is_array($dn)) {
|
||||
|
@ -2460,7 +2459,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Boolean
|
||||
*/
|
||||
function getDN($format = FILE_X509_DN_ARRAY, $dn = NULL)
|
||||
function getDN($format = FILE_X509_DN_ARRAY, $dn = null)
|
||||
{
|
||||
if (!isset($dn)) {
|
||||
$dn = isset($this->currentCert['tbsCertList']) ? $this->currentCert['tbsCertList']['issuer'] : $this->dn;
|
||||
|
@ -2524,7 +2523,7 @@ class File_X509 {
|
|||
case FILE_X509_DN_HASH:
|
||||
$dn = $this->getDN(FILE_X509_DN_CANON, $dn);
|
||||
if (!class_exists('Crypt_Hash')) {
|
||||
require_once('Crypt/Hash.php');
|
||||
include_once 'Crypt/Hash.php';
|
||||
}
|
||||
$hash = new Crypt_Hash('sha1');
|
||||
$hash = $hash->hash($dn);
|
||||
|
@ -2676,7 +2675,7 @@ class File_X509 {
|
|||
{
|
||||
switch (true) {
|
||||
case !empty($this->dn):
|
||||
return $this->getDNProp($propName, NULL, $withType);
|
||||
return $this->getDNProp($propName, null, $withType);
|
||||
case !isset($this->currentCert) || !is_array($this->currentCert):
|
||||
break;
|
||||
case isset($this->currentCert['tbsCertificate']):
|
||||
|
@ -2792,7 +2791,7 @@ class File_X509 {
|
|||
switch ($keyinfo['algorithm']['algorithm']) {
|
||||
case 'rsaEncryption':
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
require_once('Crypt/RSA.php');
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
$publicKey = new Crypt_RSA();
|
||||
$publicKey->loadKey($key);
|
||||
|
@ -2865,17 +2864,17 @@ class File_X509 {
|
|||
switch ($algorithm) {
|
||||
case 'rsaEncryption':
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
require_once('Crypt/RSA.php');
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
$this->publicKey = new Crypt_RSA();
|
||||
$this->publicKey->loadKey($key);
|
||||
$this->publicKey->setPublicKey();
|
||||
break;
|
||||
default:
|
||||
$this->publicKey = NULL;
|
||||
$this->publicKey = null;
|
||||
}
|
||||
|
||||
$this->currentKeyIdentifier = NULL;
|
||||
$this->currentKeyIdentifier = null;
|
||||
$this->currentCert = $csr;
|
||||
|
||||
return $csr;
|
||||
|
@ -2902,8 +2901,8 @@ class File_X509 {
|
|||
default:
|
||||
switch ($algorithm) {
|
||||
case 'rsaEncryption':
|
||||
$csr['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey'] =
|
||||
base64_encode("\0" . base64_decode(preg_replace('#-.+-|[\r\n]#', '', $csr['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey'])));
|
||||
$csr['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey']
|
||||
= base64_encode("\0" . base64_decode(preg_replace('#-.+-|[\r\n]#', '', $csr['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey'])));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2912,8 +2911,8 @@ class File_X509 {
|
|||
$asn1->loadOIDs($this->oids);
|
||||
|
||||
$filters = array();
|
||||
$filters['certificationRequestInfo']['subject']['rdnSequence']['value'] =
|
||||
array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
$filters['certificationRequestInfo']['subject']['rdnSequence']['value']
|
||||
= array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
|
||||
$asn1->loadFilters($filters);
|
||||
|
||||
|
@ -2990,17 +2989,17 @@ class File_X509 {
|
|||
switch ($algorithm) {
|
||||
case 'rsaEncryption':
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
require_once('Crypt/RSA.php');
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
$this->publicKey = new Crypt_RSA();
|
||||
$this->publicKey->loadKey($key);
|
||||
$this->publicKey->setPublicKey();
|
||||
break;
|
||||
default:
|
||||
$this->publicKey = NULL;
|
||||
$this->publicKey = null;
|
||||
}
|
||||
|
||||
$this->currentKeyIdentifier = NULL;
|
||||
$this->currentKeyIdentifier = null;
|
||||
$this->currentCert = $spkac;
|
||||
|
||||
return $spkac;
|
||||
|
@ -3048,14 +3047,14 @@ class File_X509 {
|
|||
$this->signatureSubject = substr($orig, $decoded[0]['content'][0]['start'], $decoded[0]['content'][0]['length']);
|
||||
|
||||
$this->_mapInExtensions($crl, 'tbsCertList/crlExtensions', $asn1);
|
||||
$rclist = &$this->_subArray($crl,'tbsCertList/revokedCertificates');
|
||||
$rclist = &$this->_subArray($crl, 'tbsCertList/revokedCertificates');
|
||||
if (is_array($rclist)) {
|
||||
foreach ($rclist as $i => $extension) {
|
||||
$this->_mapInExtensions($rclist, "$i/crlEntryExtensions", $asn1);
|
||||
}
|
||||
}
|
||||
|
||||
$this->currentKeyIdentifier = NULL;
|
||||
$this->currentKeyIdentifier = null;
|
||||
$this->currentCert = $crl;
|
||||
|
||||
return $crl;
|
||||
|
@ -3080,25 +3079,27 @@ class File_X509 {
|
|||
$asn1->loadOIDs($this->oids);
|
||||
|
||||
$filters = array();
|
||||
$filters['tbsCertList']['issuer']['rdnSequence']['value'] =
|
||||
$filters['tbsCertList']['signature']['parameters'] =
|
||||
$filters['signatureAlgorithm']['parameters'] =
|
||||
array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
$filters['tbsCertList']['issuer']['rdnSequence']['value']
|
||||
= array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
$filters['tbsCertList']['signature']['parameters']
|
||||
= array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
$filters['signatureAlgorithm']['parameters']
|
||||
= array('type' => FILE_ASN1_TYPE_UTF8_STRING);
|
||||
|
||||
if (empty($crl['tbsCertList']['signature']['parameters'])) {
|
||||
$filters['tbsCertList']['signature']['parameters'] =
|
||||
array('type' => FILE_ASN1_TYPE_NULL);
|
||||
$filters['tbsCertList']['signature']['parameters']
|
||||
= array('type' => FILE_ASN1_TYPE_NULL);
|
||||
}
|
||||
|
||||
if (empty($crl['signatureAlgorithm']['parameters'])) {
|
||||
$filters['signatureAlgorithm']['parameters'] =
|
||||
array('type' => FILE_ASN1_TYPE_NULL);
|
||||
$filters['signatureAlgorithm']['parameters']
|
||||
= array('type' => FILE_ASN1_TYPE_NULL);
|
||||
}
|
||||
|
||||
$asn1->loadFilters($filters);
|
||||
|
||||
$this->_mapOutExtensions($crl, 'tbsCertList/crlExtensions', $asn1);
|
||||
$rclist = &$this->_subArray($crl,'tbsCertList/revokedCertificates');
|
||||
$rclist = &$this->_subArray($crl, 'tbsCertList/revokedCertificates');
|
||||
if (is_array($rclist)) {
|
||||
foreach ($rclist as $i => $extension) {
|
||||
$this->_mapOutExtensions($rclist, "$i/crlEntryExtensions", $asn1);
|
||||
|
@ -3139,14 +3140,14 @@ class File_X509 {
|
|||
return false;
|
||||
}
|
||||
|
||||
$currentCert = isset($this->currentCert) ? $this->currentCert : NULL;
|
||||
$signatureSubject = isset($this->signatureSubject) ? $this->signatureSubject: NULL;
|
||||
$currentCert = isset($this->currentCert) ? $this->currentCert : null;
|
||||
$signatureSubject = isset($this->signatureSubject) ? $this->signatureSubject: null;
|
||||
|
||||
if (isset($subject->currentCert) && is_array($subject->currentCert) && isset($subject->currentCert['tbsCertificate'])) {
|
||||
$this->currentCert = $subject->currentCert;
|
||||
$this->currentCert['tbsCertificate']['signature']['algorithm'] =
|
||||
$this->currentCert['signatureAlgorithm']['algorithm'] =
|
||||
$signatureAlgorithm;
|
||||
$this->currentCert['tbsCertificate']['signature']['algorithm'] = $signatureAlgorithm;
|
||||
$this->currentCert['signatureAlgorithm']['algorithm'] = $signatureAlgorithm;
|
||||
|
||||
if (!empty($this->startDate)) {
|
||||
$this->currentCert['tbsCertificate']['validity']['notBefore']['generalTime'] = $this->startDate;
|
||||
unset($this->currentCert['tbsCertificate']['validity']['notBefore']['utcTime']);
|
||||
|
@ -3312,12 +3313,11 @@ class File_X509 {
|
|||
}
|
||||
$this->publicKey = $origPublicKey;
|
||||
|
||||
$currentCert = isset($this->currentCert) ? $this->currentCert : NULL;
|
||||
$signatureSubject = isset($this->signatureSubject) ? $this->signatureSubject: NULL;
|
||||
$currentCert = isset($this->currentCert) ? $this->currentCert : null;
|
||||
$signatureSubject = isset($this->signatureSubject) ? $this->signatureSubject: null;
|
||||
|
||||
if (isset($this->currentCert) && is_array($this->currentCert) && isset($this->currentCert['certificationRequestInfo'])) {
|
||||
$this->currentCert['signatureAlgorithm']['algorithm'] =
|
||||
$signatureAlgorithm;
|
||||
$this->currentCert['signatureAlgorithm']['algorithm'] = $signatureAlgorithm;
|
||||
if (!empty($this->dn)) {
|
||||
$this->currentCert['certificationRequestInfo']['subject'] = $this->dn;
|
||||
}
|
||||
|
@ -3366,8 +3366,8 @@ class File_X509 {
|
|||
return false;
|
||||
}
|
||||
|
||||
$currentCert = isset($this->currentCert) ? $this->currentCert : NULL;
|
||||
$signatureSubject = isset($this->signatureSubject) ? $this->signatureSubject : NULL;
|
||||
$currentCert = isset($this->currentCert) ? $this->currentCert : null;
|
||||
$signatureSubject = isset($this->signatureSubject) ? $this->signatureSubject : null;
|
||||
$thisUpdate = !empty($this->startDate) ? $this->startDate : @date('D, d M y H:i:s O');
|
||||
|
||||
if (isset($crl->currentCert) && is_array($crl->currentCert) && isset($crl->currentCert['tbsCertList'])) {
|
||||
|
@ -3400,10 +3400,9 @@ class File_X509 {
|
|||
|
||||
if (!empty($this->serialNumber)) {
|
||||
$crlNumber = $this->serialNumber;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$crlNumber = $this->getExtension('id-ce-cRLNumber');
|
||||
$crlNumber = $crlNumber !== false ? $crlNumber->add(new Math_BigInteger(1)) : NULL;
|
||||
$crlNumber = $crlNumber !== false ? $crlNumber->add(new Math_BigInteger(1)) : null;
|
||||
}
|
||||
|
||||
$this->removeExtension('id-ce-authorityKeyIdentifier');
|
||||
|
@ -3414,8 +3413,7 @@ class File_X509 {
|
|||
if (!$version) {
|
||||
if (!empty($tbsCertList['crlExtensions'])) {
|
||||
$version = 1; // v2.
|
||||
}
|
||||
elseif (!empty($tbsCertList['revokedCertificates'])) {
|
||||
} elseif (!empty($tbsCertList['revokedCertificates'])) {
|
||||
foreach ($tbsCertList['revokedCertificates'] as $cert) {
|
||||
if (!empty($cert['crlEntryExtensions'])) {
|
||||
$version = 1; // v2.
|
||||
|
@ -3613,7 +3611,7 @@ class File_X509 {
|
|||
* @access private
|
||||
* @return array ref or false
|
||||
*/
|
||||
function &_extensions(&$root, $path = NULL, $create = false)
|
||||
function &_extensions(&$root, $path = null, $create = false)
|
||||
{
|
||||
if (!isset($root)) {
|
||||
$root = $this->currentCert;
|
||||
|
@ -3667,7 +3665,7 @@ class File_X509 {
|
|||
* @access private
|
||||
* @return Boolean
|
||||
*/
|
||||
function _removeExtension($id, $path = NULL)
|
||||
function _removeExtension($id, $path = null)
|
||||
{
|
||||
$extensions = &$this->_extensions($this->currentCert, $path);
|
||||
|
||||
|
@ -3698,7 +3696,7 @@ class File_X509 {
|
|||
* @access private
|
||||
* @return Mixed
|
||||
*/
|
||||
function _getExtension($id, $cert = NULL, $path = NULL)
|
||||
function _getExtension($id, $cert = null, $path = null)
|
||||
{
|
||||
$extensions = $this->_extensions($cert, $path);
|
||||
|
||||
|
@ -3723,7 +3721,7 @@ class File_X509 {
|
|||
* @access private
|
||||
* @return Array
|
||||
*/
|
||||
function _getExtensions($cert = NULL, $path = NULL)
|
||||
function _getExtensions($cert = null, $path = null)
|
||||
{
|
||||
$exts = $this->_extensions($cert, $path);
|
||||
$extensions = array();
|
||||
|
@ -3748,7 +3746,7 @@ class File_X509 {
|
|||
* @access private
|
||||
* @return Boolean
|
||||
*/
|
||||
function _setExtension($id, $value, $critical = false, $replace = true, $path = NULL)
|
||||
function _setExtension($id, $value, $critical = false, $replace = true, $path = null)
|
||||
{
|
||||
$extensions = &$this->_extensions($this->currentCert, $path, true);
|
||||
|
||||
|
@ -3795,7 +3793,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Mixed
|
||||
*/
|
||||
function getExtension($id, $cert = NULL)
|
||||
function getExtension($id, $cert = null)
|
||||
{
|
||||
return $this->_getExtension($id, $cert);
|
||||
}
|
||||
|
@ -3807,7 +3805,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Array
|
||||
*/
|
||||
function getExtensions($cert = NULL)
|
||||
function getExtensions($cert = null)
|
||||
{
|
||||
return $this->_getExtensions($cert);
|
||||
}
|
||||
|
@ -3886,7 +3884,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Mixed
|
||||
*/
|
||||
function getAttribute($id, $disposition = FILE_X509_ATTR_ALL, $csr = NULL)
|
||||
function getAttribute($id, $disposition = FILE_X509_ATTR_ALL, $csr = null)
|
||||
{
|
||||
if (empty($csr)) {
|
||||
$csr = $this->currentCert;
|
||||
|
@ -3926,7 +3924,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Array
|
||||
*/
|
||||
function getAttributes($csr = NULL)
|
||||
function getAttributes($csr = null)
|
||||
{
|
||||
if (empty($csr)) {
|
||||
$csr = $this->currentCert;
|
||||
|
@ -4035,7 +4033,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return String binary key identifier
|
||||
*/
|
||||
function computeKeyIdentifier($key = NULL, $method = 1)
|
||||
function computeKeyIdentifier($key = null, $method = 1)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
$key = $this;
|
||||
|
@ -4064,7 +4062,7 @@ class File_X509 {
|
|||
$raw = base64_decode($raw);
|
||||
// If the key is private, compute identifier from its corresponding public key.
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
require_once('Crypt/RSA.php');
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
$key = new Crypt_RSA();
|
||||
if (!$key->loadKey($raw)) {
|
||||
|
@ -4096,7 +4094,7 @@ class File_X509 {
|
|||
|
||||
// Now we have the key string: compute its sha-1 sum.
|
||||
if (!class_exists('Crypt_Hash')) {
|
||||
require_once('Crypt/Hash.php');
|
||||
include_once 'Crypt/Hash.php';
|
||||
}
|
||||
$hash = new Crypt_Hash('sha1');
|
||||
$hash = $hash->hash($key);
|
||||
|
@ -4228,7 +4226,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Boolean
|
||||
*/
|
||||
function revoke($serial, $date = NULL)
|
||||
function revoke($serial, $date = null)
|
||||
{
|
||||
if (isset($this->currentCert['tbsCertList'])) {
|
||||
if (is_array($rclist = &$this->_subArray($this->currentCert, 'tbsCertList/revokedCertificates', true))) {
|
||||
|
@ -4293,7 +4291,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function listRevoked($crl = NULL)
|
||||
function listRevoked($crl = null)
|
||||
{
|
||||
if (!isset($crl)) {
|
||||
$crl = $this->currentCert;
|
||||
|
@ -4344,7 +4342,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Mixed
|
||||
*/
|
||||
function getRevokedCertificateExtension($serial, $id, $crl = NULL)
|
||||
function getRevokedCertificateExtension($serial, $id, $crl = null)
|
||||
{
|
||||
if (!isset($crl)) {
|
||||
$crl = $this->currentCert;
|
||||
|
@ -4367,7 +4365,7 @@ class File_X509 {
|
|||
* @access public
|
||||
* @return Array
|
||||
*/
|
||||
function getRevokedCertificateExtensions($serial, $crl = NULL)
|
||||
function getRevokedCertificateExtensions($serial, $crl = null)
|
||||
{
|
||||
if (!isset($crl)) {
|
||||
$crl = $this->currentCert;
|
||||
|
@ -4415,15 +4413,15 @@ class File_X509 {
|
|||
*/
|
||||
function _extractBER($str)
|
||||
{
|
||||
/*
|
||||
X.509 certs are assumed to be base64 encoded but sometimes they'll have additional things in them above and beyond the ceritificate. ie.
|
||||
some may have the following preceding the -----BEGIN CERTIFICATE----- line:
|
||||
|
||||
Bag Attributes
|
||||
localKeyID: 01 00 00 00
|
||||
subject=/O=organization/OU=org unit/CN=common name
|
||||
issuer=/O=organization/CN=common name
|
||||
*/
|
||||
/* X.509 certs are assumed to be base64 encoded but sometimes they'll have additional things in them
|
||||
* above and beyond the ceritificate.
|
||||
* ie. some may have the following preceding the -----BEGIN CERTIFICATE----- line:
|
||||
*
|
||||
* Bag Attributes
|
||||
* localKeyID: 01 00 00 00
|
||||
* subject=/O=organization/OU=org unit/CN=common name
|
||||
* issuer=/O=organization/CN=common name
|
||||
*/
|
||||
$temp = preg_replace('#.*?^-+[^-]+-+#ms', '', $str, 1);
|
||||
// remove the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- stuff
|
||||
$temp = preg_replace('#-+[^-]+-+#', '', $temp);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP arbitrary precision integer arithmetic library.
|
||||
|
@ -9,7 +8,7 @@
|
|||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the
|
||||
* {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the
|
||||
* {@link MATH_BIGINTEGER_MODE_INTERNAL MATH_BIGINTEGER_MODE_INTERNAL} mode)
|
||||
*
|
||||
* Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and
|
||||
|
@ -53,10 +52,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -65,12 +64,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Math
|
||||
* @package Math_BigInteger
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVI Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
* @category Math
|
||||
* @package Math_BigInteger
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVI Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
|
@ -174,12 +173,13 @@ define('MATH_BIGINTEGER_KARATSUBA_CUTOFF', 25);
|
|||
* Pure-PHP arbitrary precision integer arithmetic library. Supports base-2, base-10, base-16, and base-256
|
||||
* numbers.
|
||||
*
|
||||
* @package Math_BigInteger
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 1.0.0RC4
|
||||
* @access public
|
||||
* @package Math_BigInteger
|
||||
*/
|
||||
class Math_BigInteger {
|
||||
class Math_BigInteger
|
||||
{
|
||||
/**
|
||||
* Holds the BigInteger's value.
|
||||
*
|
||||
|
@ -223,7 +223,7 @@ class Math_BigInteger {
|
|||
/**
|
||||
* Mode independent value used for serialization.
|
||||
*
|
||||
* If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for
|
||||
* If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for
|
||||
* a variable that'll be serializable regardless of whether or not extensions are being used. Unlike $this->value,
|
||||
* however, $this->hex is only calculated when $this->__sleep() is called.
|
||||
*
|
||||
|
@ -797,7 +797,7 @@ class Math_BigInteger {
|
|||
$vars[] = 'precision';
|
||||
}
|
||||
return $vars;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2279,7 +2279,7 @@ class Math_BigInteger {
|
|||
/**
|
||||
* Montgomery Multiply
|
||||
*
|
||||
* Interleaves the montgomery reduction and long multiplication algorithms together as described in
|
||||
* Interleaves the montgomery reduction and long multiplication algorithms together as described in
|
||||
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=13 HAC 14.36}
|
||||
*
|
||||
* @see _prepMontgomery()
|
||||
|
@ -2359,7 +2359,7 @@ class Math_BigInteger {
|
|||
* {@link http://groups.google.com/group/sci.crypt/msg/7a137205c1be7d85}
|
||||
*
|
||||
* As for why we do all the bitmasking... strange things can happen when converting from floats to ints. For
|
||||
* instance, on some computers, var_dump((int) -4294967297) yields int(-1) and on others, it yields
|
||||
* instance, on some computers, var_dump((int) -4294967297) yields int(-1) and on others, it yields
|
||||
* int(-2147483648). To avoid problems stemming from this, we use bitmasks to guarantee that ints aren't
|
||||
* auto-converted to floats. The outermost bitmask is present because without it, there's no guarantee that
|
||||
* the "residue" returned would be the so-called "common residue". We use fmod, in the last step, because the
|
||||
|
@ -3290,7 +3290,7 @@ class Math_BigInteger {
|
|||
* @return Boolean
|
||||
* @access public
|
||||
* @internal Uses the
|
||||
* {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See
|
||||
* {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See
|
||||
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24}.
|
||||
*/
|
||||
function isPrime($t = false)
|
||||
|
@ -3299,6 +3299,7 @@ class Math_BigInteger {
|
|||
|
||||
if (!$t) {
|
||||
// see HAC 4.49 "Note (controlling the error probability)"
|
||||
// @codingStandardsIgnoreStart
|
||||
if ($length >= 163) { $t = 2; } // floor(1300 / 8)
|
||||
else if ($length >= 106) { $t = 3; } // floor( 850 / 8)
|
||||
else if ($length >= 81 ) { $t = 4; } // floor( 650 / 8)
|
||||
|
@ -3311,6 +3312,7 @@ class Math_BigInteger {
|
|||
else if ($length >= 25 ) { $t = 15; } // floor( 200 / 8)
|
||||
else if ($length >= 18 ) { $t = 18; } // floor( 150 / 8)
|
||||
else { $t = 27; }
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
// ie. gmp_testbit($this, 0)
|
||||
|
@ -3339,16 +3341,16 @@ class Math_BigInteger {
|
|||
|
||||
if (!isset($primes)) {
|
||||
$primes = array(
|
||||
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
|
||||
61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
|
||||
139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
|
||||
229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
|
||||
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
|
||||
421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
|
||||
521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617,
|
||||
619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
|
||||
733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
|
||||
839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
|
||||
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
|
||||
61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
|
||||
139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
|
||||
229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
|
||||
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
|
||||
421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
|
||||
521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617,
|
||||
619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
|
||||
733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
|
||||
839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
|
||||
953, 967, 971, 977, 983, 991, 997
|
||||
);
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of SCP.
|
||||
|
@ -30,10 +29,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -42,12 +41,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_SCP
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMX Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Net
|
||||
* @package Net_SCP
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMX Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
|
@ -82,12 +81,13 @@ define('NET_SCP_SSH2', 2);
|
|||
/**
|
||||
* Pure-PHP implementations of SCP.
|
||||
*
|
||||
* @package Net_SCP
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Net_SCP
|
||||
*/
|
||||
class Net_SCP {
|
||||
class Net_SCP
|
||||
{
|
||||
/**
|
||||
* SSH Object
|
||||
*
|
||||
|
@ -151,7 +151,7 @@ class Net_SCP {
|
|||
* So, for example, if you set $data to 'filename.ext' and then do Net_SCP::get(), you will get a file, twelve bytes
|
||||
* long, containing 'filename.ext' as its contents.
|
||||
*
|
||||
* Setting $mode to NET_SCP_LOCAL_FILE will change the above behavior. With NET_SCP_LOCAL_FILE, $remote_file will
|
||||
* Setting $mode to NET_SCP_LOCAL_FILE will change the above behavior. With NET_SCP_LOCAL_FILE, $remote_file will
|
||||
* contain as many bytes as filename.ext does on your local filesystem. If your filename.ext is 1MB then that is how
|
||||
* large $remote_file will be, as well.
|
||||
*
|
||||
|
@ -181,7 +181,7 @@ class Net_SCP {
|
|||
}
|
||||
|
||||
if ($this->mode == NET_SCP_SSH2) {
|
||||
$this->packet_size = $this->ssh->packet_size_client_to_server[NET_SSH2_CHANNEL_EXEC];
|
||||
$this->packet_size = $this->ssh->packet_size_client_to_server[NET_SSH2_CHANNEL_EXEC] - 4;
|
||||
}
|
||||
|
||||
$remote_file = basename($remote_file);
|
||||
|
@ -353,7 +353,7 @@ class Net_SCP {
|
|||
{
|
||||
switch ($this->mode) {
|
||||
case NET_SCP_SSH2:
|
||||
$this->ssh->_close_channel(NET_SSH2_CHANNEL_EXEC);
|
||||
$this->ssh->_close_channel(NET_SSH2_CHANNEL_EXEC, true);
|
||||
break;
|
||||
case NET_SCP_SSH1:
|
||||
$this->ssh->disconnect();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of SFTP.
|
||||
|
@ -34,10 +33,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -46,19 +45,19 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_SFTP
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMIX Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Net
|
||||
* @package Net_SFTP
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMIX Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include Net_SSH2
|
||||
*/
|
||||
if (!class_exists('Net_SSH2')) {
|
||||
require_once('SSH2.php');
|
||||
include_once 'SSH2.php';
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
@ -116,12 +115,13 @@ define('NET_SFTP_RESUME_START', 8);
|
|||
/**
|
||||
* Pure-PHP implementations of SFTP.
|
||||
*
|
||||
* @package Net_SFTP
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Net_SFTP
|
||||
*/
|
||||
class Net_SFTP extends Net_SSH2 {
|
||||
class Net_SFTP extends Net_SSH2
|
||||
{
|
||||
/**
|
||||
* Packet Types
|
||||
*
|
||||
|
@ -233,7 +233,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
* Directory Cache
|
||||
*
|
||||
* Rather than always having to open a directory and close it immediately there after to see if a file is a directory or
|
||||
* rather than always
|
||||
* rather than always
|
||||
*
|
||||
* @see Net_SFTP::_save_dir()
|
||||
* @see Net_SFTP::_remove_dir()
|
||||
|
@ -347,7 +347,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
0x00000004 => 'NET_SFTP_ATTR_PERMISSIONS',
|
||||
0x00000008 => 'NET_SFTP_ATTR_ACCESSTIME',
|
||||
// 0x80000000 will yield a floating point on 32-bit systems and converting floating points to integers
|
||||
// yields inconsistent behavior depending on how php is compiled. so we left shift -1 (which, in
|
||||
// yields inconsistent behavior depending on how php is compiled. so we left shift -1 (which, in
|
||||
// two's compliment, consists of all 1 bits) by 31. on 64-bit systems this'll yield 0xFFFFFFFF80000000.
|
||||
// that's not a problem, however, and 'anded' and a 32-bit number, as all the leading 1 bits are ignored.
|
||||
-1 << 31 => 'NET_SFTP_ATTR_EXTENDED'
|
||||
|
@ -402,7 +402,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
function login($username)
|
||||
{
|
||||
$args = func_get_args();
|
||||
if (!call_user_func_array(array('Net_SSH2', 'login'), $args)) {
|
||||
if (!call_user_func_array(array(&$this, '_login'), $args)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,11 @@ class Net_SFTP extends Net_SSH2 {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($dir[strlen($dir) - 1] != '/') {
|
||||
// assume current dir if $dir is empty
|
||||
if ($dir === '') {
|
||||
$dir = './';
|
||||
// suffix a slash if needed
|
||||
} elseif ($dir[strlen($dir) - 1] != '/') {
|
||||
$dir.= '/';
|
||||
}
|
||||
|
||||
|
@ -1038,7 +1042,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
*/
|
||||
function truncate($filename, $new_size)
|
||||
{
|
||||
$attr = pack('N3', NET_SFTP_ATTR_SIZE, $new_size / 0x100000000, $new_size);
|
||||
$attr = pack('N3', NET_SFTP_ATTR_SIZE, $new_size / 4294967296, $new_size); // 4294967296 == 0x100000000 == 1<<32
|
||||
|
||||
return $this->_setstat($filename, $attr, false);
|
||||
}
|
||||
|
@ -1054,7 +1058,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
* @return Boolean
|
||||
* @access public
|
||||
*/
|
||||
function touch($filename, $time = NULL, $atime = NULL)
|
||||
function touch($filename, $time = null, $atime = null)
|
||||
{
|
||||
if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
|
||||
return false;
|
||||
|
@ -1097,7 +1101,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
/**
|
||||
* Changes file or directory owner
|
||||
*
|
||||
* Returns TRUE on success or FALSE on error.
|
||||
* Returns true on success or false on error.
|
||||
*
|
||||
* @param String $filename
|
||||
* @param Integer $uid
|
||||
|
@ -1117,7 +1121,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
/**
|
||||
* Changes file or directory group
|
||||
*
|
||||
* Returns TRUE on success or FALSE on error.
|
||||
* Returns true on success or false on error.
|
||||
*
|
||||
* @param String $filename
|
||||
* @param Integer $gid
|
||||
|
@ -1135,8 +1139,8 @@ class Net_SFTP extends Net_SSH2 {
|
|||
/**
|
||||
* Set permissions on a file.
|
||||
*
|
||||
* Returns the new file permissions on success or FALSE on error.
|
||||
* If $recursive is true than this just returns TRUE or FALSE.
|
||||
* Returns the new file permissions on success or false on error.
|
||||
* If $recursive is true than this just returns true or false.
|
||||
*
|
||||
* @param Integer $mode
|
||||
* @param String $filename
|
||||
|
@ -1216,7 +1220,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
}
|
||||
|
||||
/*
|
||||
"Because some systems must use separate system calls to set various attributes, it is possible that a failure
|
||||
"Because some systems must use separate system calls to set various attributes, it is possible that a failure
|
||||
response will be returned, but yet some of the attributes may be have been successfully modified. If possible,
|
||||
servers SHOULD avoid this situation; however, clients MUST be aware that this is possible."
|
||||
|
||||
|
@ -1326,7 +1330,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
}
|
||||
|
||||
$dir = $this->_realpath($dir);
|
||||
// by not providing any permissions, hopefully the server will use the logged in users umask - their
|
||||
// by not providing any permissions, hopefully the server will use the logged in users umask - their
|
||||
// default permissions.
|
||||
$attr = $mode == -1 ? "\0\0\0\0" : pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
|
||||
|
||||
|
@ -1424,7 +1428,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
* So, for example, if you set $data to 'filename.ext' and then do Net_SFTP::get(), you will get a file, twelve bytes
|
||||
* long, containing 'filename.ext' as its contents.
|
||||
*
|
||||
* Setting $mode to NET_SFTP_LOCAL_FILE will change the above behavior. With NET_SFTP_LOCAL_FILE, $remote_file will
|
||||
* Setting $mode to NET_SFTP_LOCAL_FILE will change the above behavior. With NET_SFTP_LOCAL_FILE, $remote_file will
|
||||
* contain as many bytes as filename.ext does on your local filesystem. If your filename.ext is 1MB then that is how
|
||||
* large $remote_file will be, as well.
|
||||
*
|
||||
|
@ -1502,8 +1506,6 @@ class Net_SFTP extends Net_SSH2 {
|
|||
return false;
|
||||
}
|
||||
|
||||
$initialize = true;
|
||||
|
||||
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.2.3
|
||||
if ($mode & NET_SFTP_LOCAL_FILE) {
|
||||
if (!is_file($data)) {
|
||||
|
@ -1537,7 +1539,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
while ($sent < $size) {
|
||||
$temp = $mode & NET_SFTP_LOCAL_FILE ? fread($fp, $sftp_packet_size) : substr($data, $sent, $sftp_packet_size);
|
||||
$subtemp = $offset + $sent;
|
||||
$packet = pack('Na*N3a*', strlen($handle), $handle, $subtemp / 0x100000000, $subtemp, strlen($temp), $temp);
|
||||
$packet = pack('Na*N3a*', strlen($handle), $handle, $subtemp / 4294967296, $subtemp, strlen($temp), $temp);
|
||||
if (!$this->_send_sftp_packet(NET_SFTP_WRITE, $packet)) {
|
||||
fclose($fp);
|
||||
return false;
|
||||
|
@ -1683,9 +1685,10 @@ class Net_SFTP extends Net_SSH2 {
|
|||
$content = '';
|
||||
}
|
||||
|
||||
$start = $offset;
|
||||
$size = $this->max_sftp_packet < $length || $length < 0 ? $this->max_sftp_packet : $length;
|
||||
while (true) {
|
||||
$packet = pack('Na*N3', strlen($handle), $handle, $offset / 0x100000000, $offset, $size);
|
||||
$packet = pack('Na*N3', strlen($handle), $handle, $offset / 4294967296, $offset, $size);
|
||||
if (!$this->_send_sftp_packet(NET_SFTP_READ, $packet)) {
|
||||
if ($local_file !== false) {
|
||||
fclose($fp);
|
||||
|
@ -1716,12 +1719,12 @@ class Net_SFTP extends Net_SSH2 {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($length > 0 && $length <= $offset - $size) {
|
||||
if ($length > 0 && $length <= $offset - $start) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($length > 0 && $length <= $offset - $size) {
|
||||
if ($length > 0 && $length <= $offset - $start) {
|
||||
if ($local_file === false) {
|
||||
$content = substr($content, 0, $length);
|
||||
} else {
|
||||
|
@ -1923,7 +1926,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
// (0xFFFFFFFF bytes), anyway. as such, we'll just represent all file sizes that are bigger than
|
||||
// 4GB as being 4GB.
|
||||
extract(unpack('Nupper/Nsize', $this->_string_shift($response, 8)));
|
||||
$attr['size'] = $upper ? 0x100000000 * $upper : 0;
|
||||
$attr['size'] = $upper ? 4294967296 * $upper : 0;
|
||||
$attr['size']+= $size < 0 ? ($size & 0x7FFFFFFF) + 0x80000000 : $size;
|
||||
break;
|
||||
case NET_SFTP_ATTR_UIDGID: // 0x00000002 (SFTPv3 only)
|
||||
|
@ -2054,7 +2057,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
$stop = strtok(microtime(), ' ') + strtok('');
|
||||
|
||||
if (defined('NET_SFTP_LOGGING')) {
|
||||
$packet_type = '-> ' . $this->packet_types[$type] .
|
||||
$packet_type = '-> ' . $this->packet_types[$type] .
|
||||
' (' . round($stop - $start, 4) . 's)';
|
||||
if (NET_SFTP_LOGGING == NET_SFTP_LOG_REALTIME) {
|
||||
echo "<pre>\r\n" . $this->_format_log(array($data), array($packet_type)) . "\r\n</pre>\r\n";
|
||||
|
@ -2130,7 +2133,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||
$packet = $this->_string_shift($this->packet_buffer, $length);
|
||||
|
||||
if (defined('NET_SFTP_LOGGING')) {
|
||||
$packet_type = '<- ' . $this->packet_types[$this->packet_type] .
|
||||
$packet_type = '<- ' . $this->packet_types[$this->packet_type] .
|
||||
' (' . round($stop - $start, 4) . 's)';
|
||||
if (NET_SFTP_LOGGING == NET_SFTP_LOG_REALTIME) {
|
||||
echo "<pre>\r\n" . $this->_format_log(array($packet), array($packet_type)) . "\r\n</pre>\r\n";
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* SFTP Stream Wrapper
|
||||
|
@ -14,10 +13,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -26,23 +25,24 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_SFTP_Stream
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXIII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Net
|
||||
* @package Net_SFTP_Stream
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXIII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
* SFTP Stream Wrapper
|
||||
*
|
||||
* @package Net_SFTP_Stream
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.3.2
|
||||
* @access public
|
||||
* @package Net_SFTP_Stream
|
||||
*/
|
||||
class Net_SFTP_Stream {
|
||||
class Net_SFTP_Stream
|
||||
{
|
||||
/**
|
||||
* SFTP instances
|
||||
*
|
||||
|
@ -134,8 +134,12 @@ class Net_SFTP_Stream {
|
|||
*/
|
||||
function Net_SFTP_Stream()
|
||||
{
|
||||
if (defined('NET_SFTP_STREAM_LOGGING')) {
|
||||
echo "__construct()\r\n";
|
||||
}
|
||||
|
||||
if (!class_exists('Net_SFTP')) {
|
||||
require_once('Net/SFTP.php');
|
||||
include_once 'Net/SFTP.php';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,7 +517,7 @@ class Net_SFTP_Stream {
|
|||
* Open directory handle
|
||||
*
|
||||
* The only $options is "whether or not to enforce safe_mode (0x04)". Since safe mode was deprecated in 5.3 and
|
||||
* removed in 5.4 I'm just going to ignore it
|
||||
* removed in 5.4 I'm just going to ignore it
|
||||
*
|
||||
* @param String $path
|
||||
* @param Integer $options
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of SSHv1.
|
||||
|
@ -36,7 +35,7 @@
|
|||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* More information on the SSHv1 specification can be found by reading
|
||||
* More information on the SSHv1 specification can be found by reading
|
||||
* {@link http://www.snailbook.com/docs/protocol-1.5.txt protocol-1.5.txt}.
|
||||
*
|
||||
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -45,10 +44,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -57,12 +56,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_SSH1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Net
|
||||
* @package Net_SSH1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
|
@ -202,11 +201,11 @@ define('NET_SSH1_LOG_COMPLEX', 2);
|
|||
/**
|
||||
* Outputs the content real-time
|
||||
*/
|
||||
define('NET_SSH2_LOG_REALTIME', 3);
|
||||
define('NET_SSH1_LOG_REALTIME', 3);
|
||||
/**
|
||||
* Dumps the content real-time to a file
|
||||
*/
|
||||
define('NET_SSH2_LOG_REALTIME_FILE', 4);
|
||||
define('NET_SSH1_LOG_REALTIME_FILE', 4);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
|
@ -226,12 +225,13 @@ define('NET_SSH1_READ_REGEX', 2);
|
|||
/**
|
||||
* Pure-PHP implementation of SSHv1.
|
||||
*
|
||||
* @package Net_SSH1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Net_SSH1
|
||||
*/
|
||||
class Net_SSH1 {
|
||||
class Net_SSH1
|
||||
{
|
||||
/**
|
||||
* The SSH identifier
|
||||
*
|
||||
|
@ -429,11 +429,35 @@ class Net_SSH1 {
|
|||
/**
|
||||
* Current Timeout
|
||||
*
|
||||
* @see Net_SSH2::_get_channel_packet()
|
||||
* @see Net_SSH1::_get_channel_packet()
|
||||
* @access private
|
||||
*/
|
||||
var $curTimeout;
|
||||
|
||||
/**
|
||||
* Log Boundary
|
||||
*
|
||||
* @see Net_SSH1::_format_log
|
||||
* @access private
|
||||
*/
|
||||
var $log_boundary = ':';
|
||||
|
||||
/**
|
||||
* Log Long Width
|
||||
*
|
||||
* @see Net_SSH1::_format_log
|
||||
* @access private
|
||||
*/
|
||||
var $log_long_width = 65;
|
||||
|
||||
/**
|
||||
* Log Short Width
|
||||
*
|
||||
* @see Net_SSH1::_format_log
|
||||
* @access private
|
||||
*/
|
||||
var $log_short_width = 16;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
|
@ -449,16 +473,16 @@ class Net_SSH1 {
|
|||
function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES)
|
||||
{
|
||||
if (!class_exists('Math_BigInteger')) {
|
||||
require_once('Math/BigInteger.php');
|
||||
include_once 'Math/BigInteger.php';
|
||||
}
|
||||
|
||||
// Include Crypt_Random
|
||||
// the class_exists() will only be called if the crypt_random_string function hasn't been defined and
|
||||
// will trigger a call to __autoload() if you're wanting to auto-load classes
|
||||
// call function_exists() a second time to stop the require_once from being called outside
|
||||
// call function_exists() a second time to stop the include_once from being called outside
|
||||
// of the auto loader
|
||||
if (!function_exists('crypt_random_string') && !class_exists('Crypt_Random') && !function_exists('crypt_random_string')) {
|
||||
require_once('Crypt/Random.php');
|
||||
include_once 'Crypt/Random.php';
|
||||
}
|
||||
|
||||
$this->protocol_flags = array(
|
||||
|
@ -603,7 +627,7 @@ class Net_SSH1 {
|
|||
// break;
|
||||
case NET_SSH1_CIPHER_DES:
|
||||
if (!class_exists('Crypt_DES')) {
|
||||
require_once('Crypt/DES.php');
|
||||
include_once 'Crypt/DES.php';
|
||||
}
|
||||
$this->crypto = new Crypt_DES();
|
||||
$this->crypto->disablePadding();
|
||||
|
@ -612,7 +636,7 @@ class Net_SSH1 {
|
|||
break;
|
||||
case NET_SSH1_CIPHER_3DES:
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$this->crypto = new Crypt_TripleDES(CRYPT_DES_MODE_3CBC);
|
||||
$this->crypto->disablePadding();
|
||||
|
@ -621,7 +645,7 @@ class Net_SSH1 {
|
|||
break;
|
||||
//case NET_SSH1_CIPHER_RC4:
|
||||
// if (!class_exists('Crypt_RC4')) {
|
||||
// require_once('Crypt/RC4.php');
|
||||
// include_once('Crypt/RC4.php');
|
||||
// }
|
||||
// $this->crypto = new Crypt_RC4();
|
||||
// $this->crypto->enableContinuousBuffer();
|
||||
|
@ -1017,7 +1041,7 @@ class Net_SSH1 {
|
|||
|
||||
if ($this->curTimeout) {
|
||||
$read = array($this->fsock);
|
||||
$write = $except = NULL;
|
||||
$write = $except = null;
|
||||
|
||||
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
|
||||
$sec = floor($this->curTimeout);
|
||||
|
@ -1253,7 +1277,7 @@ class Net_SSH1 {
|
|||
{
|
||||
/*
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
require_once('Crypt/RSA.php');
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
|
||||
$rsa = new Crypt_RSA();
|
||||
|
@ -1318,7 +1342,7 @@ class Net_SSH1 {
|
|||
/**
|
||||
* Returns a log of the packets that have been sent and received.
|
||||
*
|
||||
* Returns a string if NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX, an array if NET_SSH2_LOGGING == NET_SSH2_LOG_SIMPLE and false if !defined('NET_SSH2_LOGGING')
|
||||
* Returns a string if NET_SSH1_LOGGING == NET_SSH1_LOG_COMPLEX, an array if NET_SSH1_LOGGING == NET_SSH1_LOG_SIMPLE and false if !defined('NET_SSH1_LOGGING')
|
||||
*
|
||||
* @access public
|
||||
* @return String or Array
|
||||
|
@ -1351,8 +1375,6 @@ class Net_SSH1 {
|
|||
*/
|
||||
function _format_log($message_log, $message_number_log)
|
||||
{
|
||||
static $boundary = ':', $long_width = 65, $short_width = 16;
|
||||
|
||||
$output = '';
|
||||
for ($i = 0; $i < count($message_log); $i++) {
|
||||
$output.= $message_number_log[$i] . "\r\n";
|
||||
|
@ -1362,19 +1384,13 @@ class Net_SSH1 {
|
|||
if (strlen($current_log)) {
|
||||
$output.= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
|
||||
}
|
||||
$fragment = $this->_string_shift($current_log, $short_width);
|
||||
$hex = substr(
|
||||
preg_replace(
|
||||
'#(.)#es',
|
||||
'"' . $boundary . '" . str_pad(dechex(ord(substr("\\1", -1))), 2, "0", STR_PAD_LEFT)',
|
||||
$fragment),
|
||||
strlen($boundary)
|
||||
);
|
||||
$fragment = $this->_string_shift($current_log, $this->log_short_width);
|
||||
$hex = substr(preg_replace_callback('#.#s', array($this, '_format_log_helper'), $fragment), strlen($this->log_boundary));
|
||||
// replace non ASCII printable characters with dots
|
||||
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
|
||||
// also replace < with a . since < messes up the output on web browsers
|
||||
$raw = preg_replace('#[^\x20-\x7E]|<#', '.', $fragment);
|
||||
$output.= str_pad($hex, $long_width - $short_width, ' ') . $raw . "\r\n";
|
||||
$output.= str_pad($hex, $this->log_long_width - $this->log_short_width, ' ') . $raw . "\r\n";
|
||||
$j++;
|
||||
} while (strlen($current_log));
|
||||
$output.= "\r\n";
|
||||
|
@ -1383,6 +1399,20 @@ class Net_SSH1 {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _format_log
|
||||
*
|
||||
* For use with preg_replace_callback()
|
||||
*
|
||||
* @param Array $matches
|
||||
* @access private
|
||||
* @return String
|
||||
*/
|
||||
function _format_log_helper($matches)
|
||||
{
|
||||
return $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the server key public exponent
|
||||
*
|
||||
|
@ -1496,57 +1526,57 @@ class Net_SSH1 {
|
|||
*/
|
||||
function _append_log($protocol_flags, $message)
|
||||
{
|
||||
switch (NET_SSH1_LOGGING) {
|
||||
// useful for benchmarks
|
||||
case NET_SSH1_LOG_SIMPLE:
|
||||
$this->protocol_flags_log[] = $protocol_flags;
|
||||
switch (NET_SSH1_LOGGING) {
|
||||
// useful for benchmarks
|
||||
case NET_SSH1_LOG_SIMPLE:
|
||||
$this->protocol_flags_log[] = $protocol_flags;
|
||||
break;
|
||||
// the most useful log for SSH1
|
||||
case NET_SSH1_LOG_COMPLEX:
|
||||
$this->protocol_flags_log[] = $protocol_flags;
|
||||
$this->_string_shift($message);
|
||||
$this->log_size+= strlen($message);
|
||||
$this->message_log[] = $message;
|
||||
while ($this->log_size > NET_SSH1_LOG_MAX_SIZE) {
|
||||
$this->log_size-= strlen(array_shift($this->message_log));
|
||||
array_shift($this->protocol_flags_log);
|
||||
}
|
||||
break;
|
||||
// dump the output out realtime; packets may be interspersed with non packets,
|
||||
// passwords won't be filtered out and select other packets may not be correctly
|
||||
// identified
|
||||
case NET_SSH1_LOG_REALTIME:
|
||||
echo "<pre>\r\n" . $this->_format_log(array($message), array($protocol_flags)) . "\r\n</pre>\r\n";
|
||||
@flush();
|
||||
@ob_flush();
|
||||
break;
|
||||
// basically the same thing as NET_SSH1_LOG_REALTIME with the caveat that NET_SSH1_LOG_REALTIME_FILE
|
||||
// needs to be defined and that the resultant log file will be capped out at NET_SSH1_LOG_MAX_SIZE.
|
||||
// the earliest part of the log file is denoted by the first <<< START >>> and is not going to necessarily
|
||||
// at the beginning of the file
|
||||
case NET_SSH1_LOG_REALTIME_FILE:
|
||||
if (!isset($this->realtime_log_file)) {
|
||||
// PHP doesn't seem to like using constants in fopen()
|
||||
$filename = NET_SSH1_LOG_REALTIME_FILE;
|
||||
$fp = fopen($filename, 'w');
|
||||
$this->realtime_log_file = $fp;
|
||||
}
|
||||
if (!is_resource($this->realtime_log_file)) {
|
||||
break;
|
||||
// the most useful log for SSH1
|
||||
case NET_SSH1_LOG_COMPLEX:
|
||||
$this->protocol_flags_log[] = $protocol_flags;
|
||||
$this->_string_shift($message);
|
||||
$this->log_size+= strlen($message);
|
||||
$this->message_log[] = $message;
|
||||
while ($this->log_size > NET_SSH2_LOG_MAX_SIZE) {
|
||||
$this->log_size-= strlen(array_shift($this->message_log));
|
||||
array_shift($this->protocol_flags_log);
|
||||
}
|
||||
break;
|
||||
// dump the output out realtime; packets may be interspersed with non packets,
|
||||
// passwords won't be filtered out and select other packets may not be correctly
|
||||
// identified
|
||||
case NET_SSH1_LOG_REALTIME:
|
||||
echo "<pre>\r\n" . $this->_format_log(array($message), array($protocol_flags)) . "\r\n</pre>\r\n";
|
||||
@flush();
|
||||
@ob_flush();
|
||||
break;
|
||||
// basically the same thing as NET_SSH1_LOG_REALTIME with the caveat that NET_SSH1_LOG_REALTIME_FILE
|
||||
// needs to be defined and that the resultant log file will be capped out at NET_SSH1_LOG_MAX_SIZE.
|
||||
// the earliest part of the log file is denoted by the first <<< START >>> and is not going to necessarily
|
||||
// at the beginning of the file
|
||||
case NET_SSH1_LOG_REALTIME_FILE:
|
||||
if (!isset($this->realtime_log_file)) {
|
||||
// PHP doesn't seem to like using constants in fopen()
|
||||
$filename = NET_SSH2_LOG_REALTIME_FILE;
|
||||
$fp = fopen($filename, 'w');
|
||||
$this->realtime_log_file = $fp;
|
||||
}
|
||||
if (!is_resource($this->realtime_log_file)) {
|
||||
break;
|
||||
}
|
||||
$entry = $this->_format_log(array($message), array($protocol_flags));
|
||||
if ($this->realtime_log_wrap) {
|
||||
$temp = "<<< START >>>\r\n";
|
||||
$entry.= $temp;
|
||||
fseek($this->realtime_log_file, ftell($this->realtime_log_file) - strlen($temp));
|
||||
}
|
||||
$this->realtime_log_size+= strlen($entry);
|
||||
if ($this->realtime_log_size > NET_SSH1_LOG_MAX_SIZE) {
|
||||
fseek($this->realtime_log_file, 0);
|
||||
$this->realtime_log_size = strlen($entry);
|
||||
$this->realtime_log_wrap = true;
|
||||
}
|
||||
fputs($this->realtime_log_file, $entry);
|
||||
}
|
||||
}
|
||||
$entry = $this->_format_log(array($message), array($protocol_flags));
|
||||
if ($this->realtime_log_wrap) {
|
||||
$temp = "<<< START >>>\r\n";
|
||||
$entry.= $temp;
|
||||
fseek($this->realtime_log_file, ftell($this->realtime_log_file) - strlen($temp));
|
||||
}
|
||||
$this->realtime_log_size+= strlen($entry);
|
||||
if ($this->realtime_log_size > NET_SSH1_LOG_MAX_SIZE) {
|
||||
fseek($this->realtime_log_file, 0);
|
||||
$this->realtime_log_size = strlen($entry);
|
||||
$this->realtime_log_wrap = true;
|
||||
}
|
||||
fputs($this->realtime_log_file, $entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of SSHv2.
|
||||
|
@ -47,10 +46,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -59,12 +58,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_SSH2
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @category Net
|
||||
* @package Net_SSH2
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMVII Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
|
@ -144,19 +143,20 @@ define('NET_SSH2_LOG_MAX_SIZE', 1024 * 1024);
|
|||
/**
|
||||
* Pure-PHP implementation of SSHv2.
|
||||
*
|
||||
* @package Net_SSH2
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access public
|
||||
* @package Net_SSH2
|
||||
*/
|
||||
class Net_SSH2 {
|
||||
class Net_SSH2
|
||||
{
|
||||
/**
|
||||
* The SSH identifier
|
||||
*
|
||||
* @var String
|
||||
* @access private
|
||||
*/
|
||||
var $identifier = 'SSH-2.0-phpseclib_0.3';
|
||||
var $identifier;
|
||||
|
||||
/**
|
||||
* The Socket Object
|
||||
|
@ -747,6 +747,30 @@ class Net_SSH2 {
|
|||
*/
|
||||
var $is_timeout = false;
|
||||
|
||||
/**
|
||||
* Log Boundary
|
||||
*
|
||||
* @see Net_SSH2::_format_log
|
||||
* @access private
|
||||
*/
|
||||
var $log_boundary = ':';
|
||||
|
||||
/**
|
||||
* Log Long Width
|
||||
*
|
||||
* @see Net_SSH2::_format_log
|
||||
* @access private
|
||||
*/
|
||||
var $log_long_width = 65;
|
||||
|
||||
/**
|
||||
* Log Short Width
|
||||
*
|
||||
* @see Net_SSH2::_format_log
|
||||
* @access private
|
||||
*/
|
||||
var $log_short_width = 16;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
|
@ -763,15 +787,15 @@ class Net_SSH2 {
|
|||
// Include Math_BigInteger
|
||||
// Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
|
||||
if (!class_exists('Math_BigInteger')) {
|
||||
require_once('Math/BigInteger.php');
|
||||
include_once 'Math/BigInteger.php';
|
||||
}
|
||||
|
||||
if (!function_exists('crypt_random_string')) {
|
||||
require_once('Crypt/Random.php');
|
||||
include_once 'Crypt/Random.php';
|
||||
}
|
||||
|
||||
if (!class_exists('Crypt_Hash')) {
|
||||
require_once('Crypt/Hash.php');
|
||||
include_once 'Crypt/Hash.php';
|
||||
}
|
||||
|
||||
$this->last_packet = strtok(microtime(), ' ') + strtok(''); // == microtime(true) in PHP5
|
||||
|
@ -861,7 +885,7 @@ class Net_SSH2 {
|
|||
}
|
||||
|
||||
$read = array($this->fsock);
|
||||
$write = $except = NULL;
|
||||
$write = $except = null;
|
||||
|
||||
$sec = floor($timeout);
|
||||
$usec = 1000000 * ($timeout - $sec);
|
||||
|
@ -895,19 +919,7 @@ class Net_SSH2 {
|
|||
return false;
|
||||
}
|
||||
|
||||
$ext = array();
|
||||
if (extension_loaded('mcrypt')) {
|
||||
$ext[] = 'mcrypt';
|
||||
}
|
||||
if (extension_loaded('gmp')) {
|
||||
$ext[] = 'gmp';
|
||||
} else if (extension_loaded('bcmath')) {
|
||||
$ext[] = 'bcmath';
|
||||
}
|
||||
|
||||
if (!empty($ext)) {
|
||||
$this->identifier.= ' (' . implode(', ', $ext) . ')';
|
||||
}
|
||||
$this->identifier = $this->_generate_identifier();
|
||||
|
||||
if (defined('NET_SSH2_LOGGING')) {
|
||||
$this->_append_log('<-', $extra . $temp);
|
||||
|
@ -944,6 +956,36 @@ class Net_SSH2 {
|
|||
$this->bitmap = NET_SSH2_MASK_CONSTRUCTOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the SSH identifier
|
||||
*
|
||||
* You should overwrite this method in your own class if you want to use another identifier
|
||||
*
|
||||
* @access protected
|
||||
* @return String
|
||||
*/
|
||||
function _generate_identifier()
|
||||
{
|
||||
$identifier = 'SSH-2.0-phpseclib_0.3';
|
||||
|
||||
$ext = array();
|
||||
if (extension_loaded('mcrypt')) {
|
||||
$ext[] = 'mcrypt';
|
||||
}
|
||||
|
||||
if (extension_loaded('gmp')) {
|
||||
$ext[] = 'gmp';
|
||||
} elseif (extension_loaded('bcmath')) {
|
||||
$ext[] = 'bcmath';
|
||||
}
|
||||
|
||||
if (!empty($ext)) {
|
||||
$identifier .= ' (' . implode(', ', $ext) . ')';
|
||||
}
|
||||
|
||||
return $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Key Exchange
|
||||
*
|
||||
|
@ -1223,23 +1265,23 @@ class Net_SSH2 {
|
|||
}
|
||||
|
||||
switch ($kex_algorithms[$i]) {
|
||||
// see http://tools.ietf.org/html/rfc2409#section-6.2 and
|
||||
// see http://tools.ietf.org/html/rfc2409#section-6.2 and
|
||||
// http://tools.ietf.org/html/rfc2412, appendex E
|
||||
case 'diffie-hellman-group1-sha1':
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
// see http://tools.ietf.org/html/rfc3526#section-3
|
||||
case 'diffie-hellman-group14-sha1':
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
|
||||
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
|
||||
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
|
||||
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
|
||||
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
|
||||
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
|
||||
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
|
||||
'3995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
}
|
||||
|
@ -1260,7 +1302,8 @@ class Net_SSH2 {
|
|||
-- http://tools.ietf.org/html/rfc4419#section-6.2 */
|
||||
$one = new Math_BigInteger(1);
|
||||
$keyLength = min($keyLength, $kexHash->getLength());
|
||||
$max = $one->bitwise_leftShift(16 * $keyLength)->subtract($one); // 2 * 8 * $keyLength
|
||||
$max = $one->bitwise_leftShift(16 * $keyLength); // 2 * 8 * $keyLength
|
||||
$max = $max->subtract($one);
|
||||
|
||||
$x = $one->random($one, $max);
|
||||
$e = $g->modPow($x, $prime);
|
||||
|
@ -1353,14 +1396,14 @@ class Net_SSH2 {
|
|||
switch ($encrypt) {
|
||||
case '3des-cbc':
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_TripleDES();
|
||||
// $this->encrypt_block_size = 64 / 8 == the default
|
||||
break;
|
||||
case '3des-ctr':
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
|
||||
// $this->encrypt_block_size = 64 / 8 == the default
|
||||
|
@ -1369,7 +1412,7 @@ class Net_SSH2 {
|
|||
case 'aes192-cbc':
|
||||
case 'aes128-cbc':
|
||||
if (!class_exists('Crypt_Rijndael')) {
|
||||
require_once('Crypt/Rijndael.php');
|
||||
include_once 'Crypt/Rijndael.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_Rijndael();
|
||||
$this->encrypt_block_size = 16; // eg. 128 / 8
|
||||
|
@ -1378,21 +1421,21 @@ class Net_SSH2 {
|
|||
case 'aes192-ctr':
|
||||
case 'aes128-ctr':
|
||||
if (!class_exists('Crypt_Rijndael')) {
|
||||
require_once('Crypt/Rijndael.php');
|
||||
include_once 'Crypt/Rijndael.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_Rijndael(CRYPT_RIJNDAEL_MODE_CTR);
|
||||
$this->encrypt_block_size = 16; // eg. 128 / 8
|
||||
break;
|
||||
case 'blowfish-cbc':
|
||||
if (!class_exists('Crypt_Blowfish')) {
|
||||
require_once('Crypt/Blowfish.php');
|
||||
include_once 'Crypt/Blowfish.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_Blowfish();
|
||||
$this->encrypt_block_size = 8;
|
||||
break;
|
||||
case 'blowfish-ctr':
|
||||
if (!class_exists('Crypt_Blowfish')) {
|
||||
require_once('Crypt/Blowfish.php');
|
||||
include_once 'Crypt/Blowfish.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
|
||||
$this->encrypt_block_size = 8;
|
||||
|
@ -1402,7 +1445,7 @@ class Net_SSH2 {
|
|||
case 'twofish256-cbc':
|
||||
case 'twofish-cbc':
|
||||
if (!class_exists('Crypt_Twofish')) {
|
||||
require_once('Crypt/Twofish.php');
|
||||
include_once 'Crypt/Twofish.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_Twofish();
|
||||
$this->encrypt_block_size = 16;
|
||||
|
@ -1411,7 +1454,7 @@ class Net_SSH2 {
|
|||
case 'twofish192-ctr':
|
||||
case 'twofish256-ctr':
|
||||
if (!class_exists('Crypt_Twofish')) {
|
||||
require_once('Crypt/Twofish.php');
|
||||
include_once 'Crypt/Twofish.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
|
||||
$this->encrypt_block_size = 16;
|
||||
|
@ -1420,7 +1463,7 @@ class Net_SSH2 {
|
|||
case 'arcfour128':
|
||||
case 'arcfour256':
|
||||
if (!class_exists('Crypt_RC4')) {
|
||||
require_once('Crypt/RC4.php');
|
||||
include_once 'Crypt/RC4.php';
|
||||
}
|
||||
$this->encrypt = new Crypt_RC4();
|
||||
break;
|
||||
|
@ -1431,13 +1474,13 @@ class Net_SSH2 {
|
|||
switch ($decrypt) {
|
||||
case '3des-cbc':
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_TripleDES();
|
||||
break;
|
||||
case '3des-ctr':
|
||||
if (!class_exists('Crypt_TripleDES')) {
|
||||
require_once('Crypt/TripleDES.php');
|
||||
include_once 'Crypt/TripleDES.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
|
||||
break;
|
||||
|
@ -1445,7 +1488,7 @@ class Net_SSH2 {
|
|||
case 'aes192-cbc':
|
||||
case 'aes128-cbc':
|
||||
if (!class_exists('Crypt_Rijndael')) {
|
||||
require_once('Crypt/Rijndael.php');
|
||||
include_once 'Crypt/Rijndael.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_Rijndael();
|
||||
$this->decrypt_block_size = 16;
|
||||
|
@ -1454,21 +1497,21 @@ class Net_SSH2 {
|
|||
case 'aes192-ctr':
|
||||
case 'aes128-ctr':
|
||||
if (!class_exists('Crypt_Rijndael')) {
|
||||
require_once('Crypt/Rijndael.php');
|
||||
include_once 'Crypt/Rijndael.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_Rijndael(CRYPT_RIJNDAEL_MODE_CTR);
|
||||
$this->decrypt_block_size = 16;
|
||||
break;
|
||||
case 'blowfish-cbc':
|
||||
if (!class_exists('Crypt_Blowfish')) {
|
||||
require_once('Crypt/Blowfish.php');
|
||||
include_once 'Crypt/Blowfish.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_Blowfish();
|
||||
$this->decrypt_block_size = 8;
|
||||
break;
|
||||
case 'blowfish-ctr':
|
||||
if (!class_exists('Crypt_Blowfish')) {
|
||||
require_once('Crypt/Blowfish.php');
|
||||
include_once 'Crypt/Blowfish.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
|
||||
$this->decrypt_block_size = 8;
|
||||
|
@ -1478,7 +1521,7 @@ class Net_SSH2 {
|
|||
case 'twofish256-cbc':
|
||||
case 'twofish-cbc':
|
||||
if (!class_exists('Crypt_Twofish')) {
|
||||
require_once('Crypt/Twofish.php');
|
||||
include_once 'Crypt/Twofish.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_Twofish();
|
||||
$this->decrypt_block_size = 16;
|
||||
|
@ -1487,7 +1530,7 @@ class Net_SSH2 {
|
|||
case 'twofish192-ctr':
|
||||
case 'twofish256-ctr':
|
||||
if (!class_exists('Crypt_Twofish')) {
|
||||
require_once('Crypt/Twofish.php');
|
||||
include_once 'Crypt/Twofish.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
|
||||
$this->decrypt_block_size = 16;
|
||||
|
@ -1496,7 +1539,7 @@ class Net_SSH2 {
|
|||
case 'arcfour128':
|
||||
case 'arcfour256':
|
||||
if (!class_exists('Crypt_RC4')) {
|
||||
require_once('Crypt/RC4.php');
|
||||
include_once 'Crypt/RC4.php';
|
||||
}
|
||||
$this->decrypt = new Crypt_RC4();
|
||||
break;
|
||||
|
@ -1647,10 +1690,26 @@ class Net_SSH2 {
|
|||
* @param Mixed $password
|
||||
* @param Mixed $...
|
||||
* @return Boolean
|
||||
* @see _login_helper
|
||||
* @see _login
|
||||
* @access public
|
||||
*/
|
||||
function login($username)
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array(&$this, '_login'), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Login Helper
|
||||
*
|
||||
* @param String $username
|
||||
* @param Mixed $password
|
||||
* @param Mixed $...
|
||||
* @return Boolean
|
||||
* @see _login_helper
|
||||
* @access private
|
||||
*/
|
||||
function _login($username)
|
||||
{
|
||||
$args = array_slice(func_get_args(), 1);
|
||||
if (empty($args)) {
|
||||
|
@ -1710,8 +1769,13 @@ class Net_SSH2 {
|
|||
}
|
||||
|
||||
// although PHP5's get_class() preserves the case, PHP4's does not
|
||||
if (is_object($password) && strtolower(get_class($password)) == 'crypt_rsa') {
|
||||
return $this->_privatekey_login($username, $password);
|
||||
if (is_object($password)) {
|
||||
switch (strtolower(get_class($password))) {
|
||||
case 'crypt_rsa':
|
||||
return $this->_privatekey_login($username, $password);
|
||||
case 'system_ssh_agent':
|
||||
return $this->_ssh_agent_login($username, $password);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($password)) {
|
||||
|
@ -1757,7 +1821,7 @@ class Net_SSH2 {
|
|||
|
||||
// remove the username and password from the logged packet
|
||||
if (!defined('NET_SSH2_LOGGING')) {
|
||||
$logged = NULL;
|
||||
$logged = null;
|
||||
} else {
|
||||
$logged = pack('CNa*Na*Na*CNa*',
|
||||
NET_SSH2_MSG_USERAUTH_REQUEST, strlen('username'), 'username', strlen('ssh-connection'), 'ssh-connection',
|
||||
|
@ -1821,7 +1885,7 @@ class Net_SSH2 {
|
|||
*/
|
||||
function _keyboard_interactive_login($username, $password)
|
||||
{
|
||||
$packet = pack('CNa*Na*Na*Na*Na*',
|
||||
$packet = pack('CNa*Na*Na*Na*Na*',
|
||||
NET_SSH2_MSG_USERAUTH_REQUEST, strlen($username), $username, strlen('ssh-connection'), 'ssh-connection',
|
||||
strlen('keyboard-interactive'), 'keyboard-interactive', 0, '', 0, ''
|
||||
);
|
||||
|
@ -1948,6 +2012,26 @@ class Net_SSH2 {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Login with an ssh-agent provided key
|
||||
*
|
||||
* @param String $username
|
||||
* @param System_SSH_Agent $agent
|
||||
* @return Boolean
|
||||
* @access private
|
||||
*/
|
||||
function _ssh_agent_login($username, $agent)
|
||||
{
|
||||
$keys = $agent->requestIdentities();
|
||||
foreach ($keys as $key) {
|
||||
if ($this->_privatekey_login($username, $key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Login with an RSA private key
|
||||
*
|
||||
|
@ -2056,7 +2140,7 @@ class Net_SSH2 {
|
|||
|
||||
/**
|
||||
* Get the output from stdError
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function getStdError()
|
||||
|
@ -2075,7 +2159,7 @@ class Net_SSH2 {
|
|||
* @return String
|
||||
* @access public
|
||||
*/
|
||||
function exec($command, $callback = NULL)
|
||||
function exec($command, $callback = null)
|
||||
{
|
||||
$this->curTimeout = $this->timeout;
|
||||
$this->is_timeout = false;
|
||||
|
@ -2086,7 +2170,7 @@ class Net_SSH2 {
|
|||
}
|
||||
|
||||
// RFC4254 defines the (client) window size as "bytes the other party can send before it must wait for the window to
|
||||
// be adjusted". 0x7FFFFFFF is, at 2GB, the max size. technically, it should probably be decremented, but,
|
||||
// be adjusted". 0x7FFFFFFF is, at 2GB, the max size. technically, it should probably be decremented, but,
|
||||
// honestly, if you're transfering more than 2GB, you probably shouldn't be using phpseclib, anyway.
|
||||
// see http://tools.ietf.org/html/rfc4254#section-5.2 for more info
|
||||
$this->window_size_server_to_client[NET_SSH2_CHANNEL_EXEC] = 0x7FFFFFFF;
|
||||
|
@ -2143,7 +2227,7 @@ class Net_SSH2 {
|
|||
// neither will your script.
|
||||
|
||||
// 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.
|
||||
$packet = pack('CNNa*CNa*',
|
||||
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SSH2_CHANNEL_EXEC], strlen('exec'), 'exec', 1, strlen($command), $command);
|
||||
|
@ -2349,7 +2433,6 @@ class Net_SSH2 {
|
|||
return false;
|
||||
}
|
||||
|
||||
$channel = $this->in_request_pty_exec ? NET_SSH2_CHANNEL_EXEC : NET_SSH2_CHANNEL_SHELL;
|
||||
return $this->_send_channel_packet($this->_get_interactive_channel(), $cmd);
|
||||
}
|
||||
|
||||
|
@ -2430,8 +2513,7 @@ class Net_SSH2 {
|
|||
*/
|
||||
function reset()
|
||||
{
|
||||
$channel = $this->in_request_pty_exec ? NET_SSH2_CHANNEL_EXEC : NET_SSH2_CHANNEL_SHELL;
|
||||
$this->_close_channel($channel);
|
||||
$this->_close_channel($this->_get_interactive_channel());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2724,7 +2806,7 @@ class Net_SSH2 {
|
|||
}
|
||||
|
||||
$read = array($this->fsock);
|
||||
$write = $except = NULL;
|
||||
$write = $except = null;
|
||||
|
||||
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
|
||||
$sec = floor($this->curTimeout);
|
||||
|
@ -2801,7 +2883,7 @@ class Net_SSH2 {
|
|||
/*
|
||||
if ($channel == NET_SSH2_CHANNEL_EXEC) {
|
||||
// SCP requires null packets, such as this, be sent. further, in the case of the ssh.com SSH server
|
||||
// this actually seems to make things twice as fast. more to the point, the message right after
|
||||
// this actually seems to make things twice as fast. more to the point, the message right after
|
||||
// SSH_MSG_CHANNEL_DATA (usually SSH_MSG_IGNORE) won't block for as long as it would have otherwise.
|
||||
// in OpenSSH it slows things down but only by a couple thousandths of a second.
|
||||
$this->_send_channel_packet($channel, chr(0));
|
||||
|
@ -2861,12 +2943,9 @@ class Net_SSH2 {
|
|||
case 'exit-status':
|
||||
extract(unpack('Cfalse/Nexit_status', $this->_string_shift($response, 5)));
|
||||
$this->exit_status = $exit_status;
|
||||
// "The channel needs to be closed with SSH_MSG_CHANNEL_CLOSE after this message."
|
||||
// -- http://tools.ietf.org/html/rfc4254#section-6.10
|
||||
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$client_channel]));
|
||||
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$channel]));
|
||||
|
||||
$this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_EOF;
|
||||
// "The client MAY ignore these messages."
|
||||
// -- http://tools.ietf.org/html/rfc4254#section-6.10
|
||||
|
||||
break;
|
||||
default:
|
||||
|
@ -2907,7 +2986,7 @@ class Net_SSH2 {
|
|||
* @return Boolean
|
||||
* @access private
|
||||
*/
|
||||
function _send_binary_packet($data, $logged = NULL)
|
||||
function _send_binary_packet($data, $logged = null)
|
||||
{
|
||||
if (!is_resource($this->fsock) || feof($this->fsock)) {
|
||||
user_error('Connection closed prematurely');
|
||||
|
@ -2967,70 +3046,70 @@ class Net_SSH2 {
|
|||
*/
|
||||
function _append_log($message_number, $message)
|
||||
{
|
||||
// remove the byte identifying the message type from all but the first two messages (ie. the identification strings)
|
||||
if (strlen($message_number) > 2) {
|
||||
$this->_string_shift($message);
|
||||
}
|
||||
// remove the byte identifying the message type from all but the first two messages (ie. the identification strings)
|
||||
if (strlen($message_number) > 2) {
|
||||
$this->_string_shift($message);
|
||||
}
|
||||
|
||||
switch (NET_SSH2_LOGGING) {
|
||||
// useful for benchmarks
|
||||
case NET_SSH2_LOG_SIMPLE:
|
||||
$this->message_number_log[] = $message_number;
|
||||
break;
|
||||
// the most useful log for SSH2
|
||||
case NET_SSH2_LOG_COMPLEX:
|
||||
$this->message_number_log[] = $message_number;
|
||||
$this->log_size+= strlen($message);
|
||||
$this->message_log[] = $message;
|
||||
while ($this->log_size > NET_SSH2_LOG_MAX_SIZE) {
|
||||
$this->log_size-= strlen(array_shift($this->message_log));
|
||||
array_shift($this->message_number_log);
|
||||
}
|
||||
break;
|
||||
// dump the output out realtime; packets may be interspersed with non packets,
|
||||
// passwords won't be filtered out and select other packets may not be correctly
|
||||
// identified
|
||||
case NET_SSH2_LOG_REALTIME:
|
||||
switch (PHP_SAPI) {
|
||||
case 'cli':
|
||||
$start = $stop = "\r\n";
|
||||
break;
|
||||
default:
|
||||
$start = '<pre>';
|
||||
$stop = '</pre>';
|
||||
}
|
||||
echo $start . $this->_format_log(array($message), array($message_number)) . $stop;
|
||||
@flush();
|
||||
@ob_flush();
|
||||
break;
|
||||
// basically the same thing as NET_SSH2_LOG_REALTIME with the caveat that NET_SSH2_LOG_REALTIME_FILE
|
||||
// needs to be defined and that the resultant log file will be capped out at NET_SSH2_LOG_MAX_SIZE.
|
||||
// the earliest part of the log file is denoted by the first <<< START >>> and is not going to necessarily
|
||||
// at the beginning of the file
|
||||
case NET_SSH2_LOG_REALTIME_FILE:
|
||||
if (!isset($this->realtime_log_file)) {
|
||||
// PHP doesn't seem to like using constants in fopen()
|
||||
$filename = NET_SSH2_LOG_REALTIME_FILENAME;
|
||||
$fp = fopen($filename, 'w');
|
||||
$this->realtime_log_file = $fp;
|
||||
}
|
||||
if (!is_resource($this->realtime_log_file)) {
|
||||
switch (NET_SSH2_LOGGING) {
|
||||
// useful for benchmarks
|
||||
case NET_SSH2_LOG_SIMPLE:
|
||||
$this->message_number_log[] = $message_number;
|
||||
break;
|
||||
// the most useful log for SSH2
|
||||
case NET_SSH2_LOG_COMPLEX:
|
||||
$this->message_number_log[] = $message_number;
|
||||
$this->log_size+= strlen($message);
|
||||
$this->message_log[] = $message;
|
||||
while ($this->log_size > NET_SSH2_LOG_MAX_SIZE) {
|
||||
$this->log_size-= strlen(array_shift($this->message_log));
|
||||
array_shift($this->message_number_log);
|
||||
}
|
||||
break;
|
||||
// dump the output out realtime; packets may be interspersed with non packets,
|
||||
// passwords won't be filtered out and select other packets may not be correctly
|
||||
// identified
|
||||
case NET_SSH2_LOG_REALTIME:
|
||||
switch (PHP_SAPI) {
|
||||
case 'cli':
|
||||
$start = $stop = "\r\n";
|
||||
break;
|
||||
}
|
||||
$entry = $this->_format_log(array($message), array($message_number));
|
||||
if ($this->realtime_log_wrap) {
|
||||
$temp = "<<< START >>>\r\n";
|
||||
$entry.= $temp;
|
||||
fseek($this->realtime_log_file, ftell($this->realtime_log_file) - strlen($temp));
|
||||
}
|
||||
$this->realtime_log_size+= strlen($entry);
|
||||
if ($this->realtime_log_size > NET_SSH2_LOG_MAX_SIZE) {
|
||||
fseek($this->realtime_log_file, 0);
|
||||
$this->realtime_log_size = strlen($entry);
|
||||
$this->realtime_log_wrap = true;
|
||||
}
|
||||
fputs($this->realtime_log_file, $entry);
|
||||
}
|
||||
default:
|
||||
$start = '<pre>';
|
||||
$stop = '</pre>';
|
||||
}
|
||||
echo $start . $this->_format_log(array($message), array($message_number)) . $stop;
|
||||
@flush();
|
||||
@ob_flush();
|
||||
break;
|
||||
// basically the same thing as NET_SSH2_LOG_REALTIME with the caveat that NET_SSH2_LOG_REALTIME_FILE
|
||||
// needs to be defined and that the resultant log file will be capped out at NET_SSH2_LOG_MAX_SIZE.
|
||||
// the earliest part of the log file is denoted by the first <<< START >>> and is not going to necessarily
|
||||
// at the beginning of the file
|
||||
case NET_SSH2_LOG_REALTIME_FILE:
|
||||
if (!isset($this->realtime_log_file)) {
|
||||
// PHP doesn't seem to like using constants in fopen()
|
||||
$filename = NET_SSH2_LOG_REALTIME_FILENAME;
|
||||
$fp = fopen($filename, 'w');
|
||||
$this->realtime_log_file = $fp;
|
||||
}
|
||||
if (!is_resource($this->realtime_log_file)) {
|
||||
break;
|
||||
}
|
||||
$entry = $this->_format_log(array($message), array($message_number));
|
||||
if ($this->realtime_log_wrap) {
|
||||
$temp = "<<< START >>>\r\n";
|
||||
$entry.= $temp;
|
||||
fseek($this->realtime_log_file, ftell($this->realtime_log_file) - strlen($temp));
|
||||
}
|
||||
$this->realtime_log_size+= strlen($entry);
|
||||
if ($this->realtime_log_size > NET_SSH2_LOG_MAX_SIZE) {
|
||||
fseek($this->realtime_log_file, 0);
|
||||
$this->realtime_log_size = strlen($entry);
|
||||
$this->realtime_log_wrap = true;
|
||||
}
|
||||
fputs($this->realtime_log_file, $entry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3103,16 +3182,19 @@ class Net_SSH2 {
|
|||
* for SCP more than anything.
|
||||
*
|
||||
* @param Integer $client_channel
|
||||
* @param Boolean $want_reply
|
||||
* @return Boolean
|
||||
* @access private
|
||||
*/
|
||||
function _close_channel($client_channel)
|
||||
function _close_channel($client_channel, $want_reply = false)
|
||||
{
|
||||
// see http://tools.ietf.org/html/rfc4254#section-5.3
|
||||
|
||||
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$client_channel]));
|
||||
|
||||
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
|
||||
if (!$want_reply) {
|
||||
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
|
||||
}
|
||||
|
||||
$this->channel_status[$client_channel] = NET_SSH2_MSG_CHANNEL_CLOSE;
|
||||
|
||||
|
@ -3120,6 +3202,10 @@ class Net_SSH2 {
|
|||
|
||||
while (!is_bool($this->_get_channel_packet($client_channel)));
|
||||
|
||||
if ($want_reply) {
|
||||
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
|
||||
}
|
||||
|
||||
if ($this->bitmap & NET_SSH2_MASK_SHELL) {
|
||||
$this->bitmap&= ~NET_SSH2_MASK_SHELL;
|
||||
}
|
||||
|
@ -3220,8 +3306,6 @@ class Net_SSH2 {
|
|||
*/
|
||||
function _format_log($message_log, $message_number_log)
|
||||
{
|
||||
static $boundary = ':', $long_width = 65, $short_width = 16;
|
||||
|
||||
$output = '';
|
||||
for ($i = 0; $i < count($message_log); $i++) {
|
||||
$output.= $message_number_log[$i] . "\r\n";
|
||||
|
@ -3231,19 +3315,13 @@ class Net_SSH2 {
|
|||
if (strlen($current_log)) {
|
||||
$output.= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
|
||||
}
|
||||
$fragment = $this->_string_shift($current_log, $short_width);
|
||||
$hex = substr(
|
||||
preg_replace(
|
||||
'#(.)#es',
|
||||
'"' . $boundary . '" . str_pad(dechex(ord(substr("\\1", -1))), 2, "0", STR_PAD_LEFT)',
|
||||
$fragment),
|
||||
strlen($boundary)
|
||||
);
|
||||
$fragment = $this->_string_shift($current_log, $this->log_short_width);
|
||||
$hex = substr(preg_replace_callback('#.#s', array($this, '_format_log_helper'), $fragment), strlen($this->log_boundary));
|
||||
// replace non ASCII printable characters with dots
|
||||
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
|
||||
// also replace < with a . since < messes up the output on web browsers
|
||||
$raw = preg_replace('#[^\x20-\x7E]|<#', '.', $fragment);
|
||||
$output.= str_pad($hex, $long_width - $short_width, ' ') . $raw . "\r\n";
|
||||
$output.= str_pad($hex, $this->log_long_width - $this->log_short_width, ' ') . $raw . "\r\n";
|
||||
$j++;
|
||||
} while (strlen($current_log));
|
||||
$output.= "\r\n";
|
||||
|
@ -3252,6 +3330,20 @@ class Net_SSH2 {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _format_log
|
||||
*
|
||||
* For use with preg_replace_callback()
|
||||
*
|
||||
* @param Array $matches
|
||||
* @access private
|
||||
* @return String
|
||||
*/
|
||||
function _format_log_helper($matches)
|
||||
{
|
||||
return $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all errors
|
||||
*
|
||||
|
@ -3505,7 +3597,7 @@ class Net_SSH2 {
|
|||
$signature = $this->_string_shift($signature, $temp['length']);
|
||||
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
require_once('Crypt/RSA.php');
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
|
||||
$rsa = new Crypt_RSA();
|
||||
|
@ -3572,7 +3664,15 @@ class Net_SSH2 {
|
|||
*/
|
||||
function _is_includable($suffix)
|
||||
{
|
||||
foreach (explode(PATH_SEPARATOR, get_include_path()) as $prefix) {
|
||||
// stream_resolve_include_path was introduced in PHP 5.3.2
|
||||
if (function_exists('stream_resolve_include_path')) {
|
||||
return stream_resolve_include_path($suffix) !== false;
|
||||
}
|
||||
|
||||
$paths = PATH_SEPARATOR == ':' ?
|
||||
preg_split('#(?<!phar):#', get_include_path()) :
|
||||
explode(PATH_SEPARATOR, get_include_path());
|
||||
foreach ($paths as $prefix) {
|
||||
$ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
|
||||
$file = $prefix . $ds . $suffix;
|
||||
|
||||
|
|
315
apps/files_external/3rdparty/phpseclib/phpseclib/System/SSH_Agent.php
vendored
Normal file
315
apps/files_external/3rdparty/phpseclib/phpseclib/System/SSH_Agent.php
vendored
Normal file
|
@ -0,0 +1,315 @@
|
|||
<?php
|
||||
/**
|
||||
* Pure-PHP ssh-agent client.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* Here are some examples of how to use this library:
|
||||
* <code>
|
||||
* <?php
|
||||
* include('System/SSH_Agent.php');
|
||||
* include('Net/SSH2.php');
|
||||
*
|
||||
* $agent = new System_SSH_Agent();
|
||||
*
|
||||
* $ssh = new Net_SSH2('www.domain.tld');
|
||||
* if (!$ssh->login('username', $agent)) {
|
||||
* exit('Login Failed');
|
||||
* }
|
||||
*
|
||||
* echo $ssh->exec('pwd');
|
||||
* echo $ssh->exec('ls -la');
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @category System
|
||||
* @package System_SSH_Agent
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright MMXIV Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
* @internal See http://api.libssh.org/rfc/PROTOCOL.agent
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
* Message numbers
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
// to request SSH1 keys you have to use SSH_AGENTC_REQUEST_RSA_IDENTITIES (1)
|
||||
define('SYSTEM_SSH_AGENTC_REQUEST_IDENTITIES', 11);
|
||||
// this is the SSH2 response; the SSH1 response is SSH_AGENT_RSA_IDENTITIES_ANSWER (2).
|
||||
define('SYSTEM_SSH_AGENT_IDENTITIES_ANSWER', 12);
|
||||
define('SYSTEM_SSH_AGENT_FAILURE', 5);
|
||||
// the SSH1 request is SSH_AGENTC_RSA_CHALLENGE (3)
|
||||
define('SYSTEM_SSH_AGENTC_SIGN_REQUEST', 13);
|
||||
// the SSH1 response is SSH_AGENT_RSA_RESPONSE (4)
|
||||
define('SYSTEM_SSH_AGENT_SIGN_RESPONSE', 14);
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Pure-PHP ssh-agent client identity object
|
||||
*
|
||||
* Instantiation should only be performed by System_SSH_Agent class.
|
||||
* This could be thought of as implementing an interface that Crypt_RSA
|
||||
* implements. ie. maybe a Net_SSH_Auth_PublicKey interface or something.
|
||||
* The methods in this interface would be getPublicKey, setSignatureMode
|
||||
* and sign since those are the methods phpseclib looks for to perform
|
||||
* public key authentication.
|
||||
*
|
||||
* @package System_SSH_Agent
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access internal
|
||||
*/
|
||||
class System_SSH_Agent_Identity
|
||||
{
|
||||
/**
|
||||
* Key Object
|
||||
*
|
||||
* @var Crypt_RSA
|
||||
* @access private
|
||||
* @see System_SSH_Agent_Identity::getPublicKey()
|
||||
*/
|
||||
var $key;
|
||||
|
||||
/**
|
||||
* Key Blob
|
||||
*
|
||||
* @var String
|
||||
* @access private
|
||||
* @see System_SSH_Agent_Identity::sign()
|
||||
*/
|
||||
var $key_blob;
|
||||
|
||||
/**
|
||||
* Socket Resource
|
||||
*
|
||||
* @var Resource
|
||||
* @access private
|
||||
* @see System_SSH_Agent_Identity::sign()
|
||||
*/
|
||||
var $fsock;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* @param Resource $fsock
|
||||
* @return System_SSH_Agent_Identity
|
||||
* @access private
|
||||
*/
|
||||
function System_SSH_Agent_Identity($fsock)
|
||||
{
|
||||
$this->fsock = $fsock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Public Key
|
||||
*
|
||||
* Called by System_SSH_Agent::requestIdentities()
|
||||
*
|
||||
* @param Crypt_RSA $key
|
||||
* @access private
|
||||
*/
|
||||
function setPublicKey($key)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->key->setPublicKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Public Key
|
||||
*
|
||||
* Called by System_SSH_Agent::requestIdentities(). The key blob could be extracted from $this->key
|
||||
* but this saves a small amount of computation.
|
||||
*
|
||||
* @param String $key_blob
|
||||
* @access private
|
||||
*/
|
||||
function setPublicKeyBlob($key_blob)
|
||||
{
|
||||
$this->key_blob = $key_blob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Public Key
|
||||
*
|
||||
* Wrapper for $this->key->getPublicKey()
|
||||
*
|
||||
* @param Integer $format optional
|
||||
* @return Mixed
|
||||
* @access public
|
||||
*/
|
||||
function getPublicKey($format = null)
|
||||
{
|
||||
return !isset($format) ? $this->key->getPublicKey() : $this->key->getPublicKey($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Signature Mode
|
||||
*
|
||||
* Doesn't do anything as ssh-agent doesn't let you pick and choose the signature mode. ie.
|
||||
* ssh-agent's only supported mode is CRYPT_RSA_SIGNATURE_PKCS1
|
||||
*
|
||||
* @param Integer $mode
|
||||
* @access public
|
||||
*/
|
||||
function setSignatureMode($mode)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a signature
|
||||
*
|
||||
* See "2.6.2 Protocol 2 private key signature request"
|
||||
*
|
||||
* @param String $message
|
||||
* @return String
|
||||
* @access public
|
||||
*/
|
||||
function sign($message)
|
||||
{
|
||||
// the last parameter (currently 0) is for flags and ssh-agent only defines one flag (for ssh-dss): SSH_AGENT_OLD_SIGNATURE
|
||||
$packet = pack('CNa*Na*N', SYSTEM_SSH_AGENTC_SIGN_REQUEST, strlen($this->key_blob), $this->key_blob, strlen($message), $message, 0);
|
||||
$packet = pack('Na*', strlen($packet), $packet);
|
||||
if (strlen($packet) != fputs($this->fsock, $packet)) {
|
||||
user_error('Connection closed during signing');
|
||||
}
|
||||
|
||||
$length = current(unpack('N', fread($this->fsock, 4)));
|
||||
$type = ord(fread($this->fsock, 1));
|
||||
if ($type != SYSTEM_SSH_AGENT_SIGN_RESPONSE) {
|
||||
user_error('Unable to retreive signature');
|
||||
}
|
||||
|
||||
$signature_blob = fread($this->fsock, $length - 1);
|
||||
// the only other signature format defined - ssh-dss - is the same length as ssh-rsa
|
||||
// the + 12 is for the other various SSH added length fields
|
||||
return substr($signature_blob, strlen('ssh-rsa') + 12);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure-PHP ssh-agent client identity factory
|
||||
*
|
||||
* requestIdentities() method pumps out System_SSH_Agent_Identity objects
|
||||
*
|
||||
* @package System_SSH_Agent
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @version 0.1.0
|
||||
* @access internal
|
||||
*/
|
||||
class System_SSH_Agent
|
||||
{
|
||||
/**
|
||||
* Socket Resource
|
||||
*
|
||||
* @var Resource
|
||||
* @access private
|
||||
*/
|
||||
var $fsock;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*
|
||||
* @return System_SSH_Agent
|
||||
* @access public
|
||||
*/
|
||||
function System_SSH_Agent()
|
||||
{
|
||||
switch (true) {
|
||||
case isset($_SERVER['SSH_AUTH_SOCK']):
|
||||
$address = $_SERVER['SSH_AUTH_SOCK'];
|
||||
break;
|
||||
case isset($_ENV['SSH_AUTH_SOCK']):
|
||||
$address = $_ENV['SSH_AUTH_SOCK'];
|
||||
break;
|
||||
default:
|
||||
user_error('SSH_AUTH_SOCK not found');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fsock = fsockopen('unix://' . $address, 0, $errno, $errstr);
|
||||
if (!$this->fsock) {
|
||||
user_error("Unable to connect to ssh-agent (Error $errno: $errstr)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request Identities
|
||||
*
|
||||
* See "2.5.2 Requesting a list of protocol 2 keys"
|
||||
* Returns an array containing zero or more System_SSH_Agent_Identity objects
|
||||
*
|
||||
* @return Array
|
||||
* @access public
|
||||
*/
|
||||
function requestIdentities()
|
||||
{
|
||||
if (!$this->fsock) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$packet = pack('NC', 1, SYSTEM_SSH_AGENTC_REQUEST_IDENTITIES);
|
||||
if (strlen($packet) != fputs($this->fsock, $packet)) {
|
||||
user_error('Connection closed while requesting identities');
|
||||
}
|
||||
|
||||
$length = current(unpack('N', fread($this->fsock, 4)));
|
||||
$type = ord(fread($this->fsock, 1));
|
||||
if ($type != SYSTEM_SSH_AGENT_IDENTITIES_ANSWER) {
|
||||
user_error('Unable to request identities');
|
||||
}
|
||||
|
||||
$identities = array();
|
||||
$keyCount = current(unpack('N', fread($this->fsock, 4)));
|
||||
for ($i = 0; $i < $keyCount; $i++) {
|
||||
$length = current(unpack('N', fread($this->fsock, 4)));
|
||||
$key_blob = fread($this->fsock, $length);
|
||||
$length = current(unpack('N', fread($this->fsock, 4)));
|
||||
$key_comment = fread($this->fsock, $length);
|
||||
$length = current(unpack('N', substr($key_blob, 0, 4)));
|
||||
$key_type = substr($key_blob, 4, $length);
|
||||
switch ($key_type) {
|
||||
case 'ssh-rsa':
|
||||
if (!class_exists('Crypt_RSA')) {
|
||||
include_once 'Crypt/RSA.php';
|
||||
}
|
||||
$key = new Crypt_RSA();
|
||||
$key->loadKey('ssh-rsa ' . base64_encode($key_blob) . ' ' . $key_comment);
|
||||
break;
|
||||
case 'ssh-dss':
|
||||
// not currently supported
|
||||
break;
|
||||
}
|
||||
// resources are passed by reference by default
|
||||
if (isset($key)) {
|
||||
$identity = new System_SSH_Agent_Identity($this->fsock);
|
||||
$identity->setPublicKey($key);
|
||||
$identity->setPublicKeyBlob($key_blob);
|
||||
$identities[] = $identity;
|
||||
unset($key);
|
||||
}
|
||||
}
|
||||
|
||||
return $identities;
|
||||
}
|
||||
}
|
|
@ -3,4 +3,4 @@
|
|||
HOME = .
|
||||
RANDFILE = $ENV::HOME/.rnd
|
||||
|
||||
[ v3_ca ]
|
||||
[ v3_ca ]
|
||||
|
|
Loading…
Reference in a new issue