Merge branch 'master' of https://github.com/phpseclib/phpseclib into openssl-support

This commit is contained in:
terrafrost 2014-12-13 14:15:34 -06:00
commit c5f74eb3a3
54 changed files with 806 additions and 373 deletions

View File

@ -20,6 +20,7 @@ env:
before_install: true
install:
- eval `ssh-agent -s`
- travis/setup-secure-shell.sh
- sh -c "if [ '$TRAVIS_PHP_VERSION' != 'hhvm' ]; then travis/install-php-extensions.sh; fi"
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.2' ]; then travis/setup-composer.sh; fi"

View File

@ -49,10 +49,10 @@
"php": ">=5.0.0"
},
"require-dev": {
"phing/phing": "2.7.*",
"phpunit/phpunit": "4.0.*",
"sami/sami": "1.*",
"squizlabs/php_codesniffer": "1.*"
"phing/phing": "~2.7",
"phpunit/phpunit": "~4.0",
"sami/sami": "~2.0",
"squizlabs/php_codesniffer": "~1.5"
},
"suggest": {
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a wide variety of cryptographic operations.",

713
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -60,7 +60,7 @@
* @category Crypt
* @package Crypt_AES
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVIII Jim Wigginton
* @copyright 2008 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -47,7 +47,7 @@
* @package Crypt_Base
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -48,7 +48,7 @@
* @package Crypt_Blowfish
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -53,7 +53,7 @@
* @category Crypt
* @package Crypt_DES
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -49,7 +49,7 @@
* @category Crypt
* @package Crypt_Hash
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -55,7 +55,7 @@
* @category Crypt
* @package Crypt_RC4
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -62,7 +62,7 @@
* @category Crypt
* @package Crypt_RSA
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMIX Jim Wigginton
* @copyright 2009 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -38,7 +38,7 @@
* @category Crypt
* @package Crypt_Random
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -65,7 +65,7 @@
* @category Crypt
* @package Crypt_Rijndael
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVIII Jim Wigginton
* @copyright 2008 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -47,7 +47,7 @@
* @category Crypt
* @package Crypt_TripleDES
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -48,7 +48,7 @@
* @package Crypt_Twofish
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -31,7 +31,7 @@
* @category File
* @package File_ANSI
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXII Jim Wigginton
* @copyright 2012 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -34,7 +34,7 @@
* @category File
* @package File_ASN1
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXII Jim Wigginton
* @copyright 2012 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -37,7 +37,7 @@
* @category File
* @package File_X509
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXII Jim Wigginton
* @copyright 2012 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -63,7 +63,7 @@
* @category Math
* @package Math_BigInteger
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVI Jim Wigginton
* @copyright 2006 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/

View File

@ -44,7 +44,7 @@
* @category Net
* @package Net_SCP
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMX Jim Wigginton
* @copyright 2010 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
@ -129,7 +129,7 @@ class Net_SCP
}
switch (strtolower(get_class($ssh))) {
case'net_ssh2':
case 'net_ssh2':
$this->mode = NET_SCP_SSH2;
break;
case 'net_ssh1':
@ -170,7 +170,7 @@ class Net_SCP
return false;
}
if (!$this->ssh->exec('scp -t "' . $remote_file . '"', false)) { // -t = to
if (!$this->ssh->exec('scp -t ' . escapeshellarg($remote_file), false)) { // -t = to
return false;
}
@ -195,7 +195,6 @@ class Net_SCP
$fp = @fopen($data, 'rb');
if (!$fp) {
fclose($fp);
return false;
}
$size = filesize($data);
@ -245,7 +244,7 @@ class Net_SCP
return false;
}
if (!$this->ssh->exec('scp -f "' . $remote_file . '"', false)) { // -f = from
if (!$this->ssh->exec('scp -f ' . escapeshellarg($remote_file), false)) { // -f = from
return false;
}

View File

@ -48,7 +48,7 @@
* @category Net
* @package Net_SFTP
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMIX Jim Wigginton
* @copyright 2009 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -28,7 +28,7 @@
* @category Net
* @package Net_SFTP_Stream
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXIII Jim Wigginton
* @copyright 2013 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -59,7 +59,7 @@
* @category Net
* @package Net_SSH1
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/

View File

@ -61,7 +61,7 @@
* @category Net
* @package Net_SSH2
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
@ -3310,27 +3310,23 @@ class Net_SSH2
*/
function _send_channel_packet($client_channel, $data)
{
/* The maximum amount of data allowed is determined by the maximum
packet size for the channel, and the current window size, whichever
is smaller.
-- http://tools.ietf.org/html/rfc4254#section-5.2 */
$max_size = min(
$this->packet_size_client_to_server[$client_channel],
$this->window_size_client_to_server[$client_channel]
);
while (strlen($data) > $max_size) {
while (strlen($data)) {
if (!$this->window_size_client_to_server[$client_channel]) {
$this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
// using an invalid channel will let the buffers be built up for the valid channels
$output = $this->_get_channel_packet(-1);
$this->_get_channel_packet(-1);
$this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
$max_size = min(
$this->packet_size_client_to_server[$client_channel],
$this->window_size_client_to_server[$client_channel]
);
}
/* The maximum amount of data allowed is determined by the maximum
packet size for the channel, and the current window size, whichever
is smaller.
-- http://tools.ietf.org/html/rfc4254#section-5.2 */
$max_size = min(
$this->packet_size_client_to_server[$client_channel],
$this->window_size_client_to_server[$client_channel]
);
$temp = $this->_string_shift($data, $max_size);
$packet = pack('CN2a*',
NET_SSH2_MSG_CHANNEL_DATA,
@ -3338,27 +3334,13 @@ class Net_SSH2
strlen($temp),
$temp
);
$this->window_size_client_to_server[$client_channel]-= strlen($temp);
if (!$this->_send_binary_packet($packet)) {
return false;
}
}
if (strlen($data) >= $this->window_size_client_to_server[$client_channel]) {
$this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
$this->_get_channel_packet(-1);
$this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
}
$this->window_size_client_to_server[$client_channel]-= strlen($data);
return $this->_send_binary_packet(pack('CN2a*',
NET_SSH2_MSG_CHANNEL_DATA,
$this->server_channels[$client_channel],
strlen($data),
$data));
return true;
}
/**

View File

@ -43,7 +43,7 @@
* @category System
* @package System_SSH_Agent
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXIV Jim Wigginton
* @copyright 2014 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

View File

@ -30,7 +30,7 @@
* @category System
* @package System_SSH_Agent
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXIV Jim Wigginton
* @copyright 2014 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

View File

@ -0,0 +1,88 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
class Functional_Net_SCPSSH2UserStoryTest extends PhpseclibFunctionalTestCase
{
static protected $remoteFile;
static protected $exampleData;
static protected $exampleDataLength;
static public function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$remoteFile = uniqid('phpseclib-scp-ssh2-') . '.txt';
self::$exampleData = str_repeat('abscp12345', 1000);
self::$exampleDataLength = 10000;
}
public function testConstructSSH2()
{
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
$this->assertTrue(
$ssh->login(
$this->getEnv('SSH_USERNAME'),
$this->getEnv('SSH_PASSWORD')
)
);
return $ssh;
}
/** @depends testConstructSSH2 */
public function testConstructor($ssh)
{
$scp = new Net_SCP($ssh);
$this->assertTrue(
is_object($scp),
'Could not construct Net_SCP object.'
);
return $scp;
}
/** @depends testConstructor */
public function testPutGetString($scp)
{
$this->assertTrue(
$scp->put(self::$remoteFile, self::$exampleData),
'Failed asserting that data could successfully be put() into file.'
);
$content = $scp->get(self::$remoteFile);
// TODO: Address https://github.com/phpseclib/phpseclib/issues/146
$this->assertContains(
strlen($content),
array(self::$exampleDataLength, self::$exampleDataLength + 1),
'Failed asserting that string length matches expected length.'
);
$this->assertContains(
$content,
array(self::$exampleData, self::$exampleData . "\0"),
'Failed asserting that string content matches expected content.'
);
return $scp;
}
/** @depends testPutGetString */
public function testGetFile($scp)
{
$localFilename = $this->createTempFile();
$this->assertTrue(
$scp->get(self::$remoteFile, $localFilename),
'Failed asserting that get() into file was successful.'
);
// TODO: Address https://github.com/phpseclib/phpseclib/issues/146
$this->assertContains(
filesize($localFilename),
array(self::$exampleDataLength, self::$exampleDataLength + 1),
'Failed asserting that filesize matches expected data size.'
);
$this->assertContains(
file_get_contents($localFilename),
array(self::$exampleData, self::$exampleData . "\0"),
'Failed asserting that file content matches expected content.'
);
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'Crypt/Base.php';
class Functional_Net_SFTPLargeFileTest extends PhpseclibFunctionalTestCase
{
protected $sftp;
protected $scratchDir;
static public function setUpBeforeClass()
{
if (!extension_loaded('mcrypt')) {
self::markTestSkipped('This test depends on mcrypt for performance.');
}
parent::setUpBeforeClass();
self::ensureConstant('CRYPT_AES_MODE', CRYPT_MODE_MCRYPT);
self::ensureConstant('CRYPT_BLOWFISH_MODE', CRYPT_MODE_MCRYPT);
self::ensureConstant('CRYPT_DES_MODE', CRYPT_MODE_MCRYPT);
self::ensureConstant('CRYPT_RC2_MODE', CRYPT_MODE_MCRYPT);
self::ensureConstant('CRYPT_RC4_MODE', CRYPT_MODE_MCRYPT);
self::ensureConstant('CRYPT_RIJNDAEL_MODE', CRYPT_MODE_MCRYPT);
self::ensureConstant('CRYPT_TWOFISH_MODE', CRYPT_MODE_MCRYPT);
}
public function setUp()
{
$this->scratchDir = uniqid('phpseclib-sftp-large-scratch-');
$this->sftp = new Net_SFTP($this->getEnv('SSH_HOSTNAME'));
$this->assertTrue($this->sftp->login(
$this->getEnv('SSH_USERNAME'),
$this->getEnv('SSH_PASSWORD')
));
$this->assertTrue($this->sftp->mkdir($this->scratchDir));
$this->assertTrue($this->sftp->chdir($this->scratchDir));
}
public function tearDown()
{
if ($this->sftp) {
$this->sftp->chdir($this->getEnv('SSH_HOME'));
$this->sftp->delete($this->scratchDir);
}
parent::tearDown();
}
/**
* @group github298
* @group github455
* @group github457
*/
public function testPutSizeLocalFile()
{
$tmp_filename = $this->createTempFile(128, 1024 * 1024);
$filename = 'file-large-from-local.txt';
$this->assertTrue(
$this->sftp->put($filename, $tmp_filename, NET_SFTP_LOCAL_FILE),
'Failed asserting that local file could be successfully put().'
);
$this->assertSame(
128 * 1024 * 1024,
$this->sftp->size($filename),
'Failed asserting that uploaded local file has the expected length.'
);
}
}

View File

@ -2,7 +2,7 @@
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
class Functional_Net_SSH2AgentTest extends PhpseclibFunctionalTestCase
{
public static function setUpBeforeClass()
{
if (!isset($_SERVER['SSH_AUTH_SOCK'])) {
self::markTestSkipped(
'This test requires an SSH Agent (SSH_AUTH_SOCK env variable).'
);
}
parent::setUpBeforeClass();
}
public function testAgentLogin()
{
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
$agent = new System_SSH_Agent;
$this->assertTrue(
$ssh->login($this->getEnv('SSH_USERNAME'), $agent),
'SSH2 login using Agent failed.'
);
}
}

View File

@ -2,7 +2,7 @@
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
@ -10,7 +10,21 @@ abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
static public function setUpBeforeClass()
{
if (extension_loaded('runkit')) {
self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP);
if (extension_loaded('gmp')) {
self::ensureConstant(
'MATH_BIGINTEGER_MODE',
MATH_BIGINTEGER_MODE_GMP
);
} elseif (extension_loaded('bcmath')) {
self::ensureConstant(
'MATH_BIGINTEGER_MODE',
MATH_BIGINTEGER_MODE_BCMATH
);
} else {
self::markTestSkipped(
'Should have gmp or bcmath extension for functional test.'
);
}
self::ensureConstant('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH);
self::reRequireFile('Math/BigInteger.php');
self::reRequireFile('Crypt/Hash.php');

View File

@ -1,12 +1,52 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
{
protected $tempFilesToUnlinkOnTearDown = array();
public function tearDown()
{
foreach ($this->tempFilesToUnlinkOnTearDown as $filename) {
if (!file_exists($filename) || unlink($filename)) {
unset($this->tempFilesToUnlinkOnTearDown[$filename]);
}
}
parent::tearDown();
}
/**
* Creates a temporary file on the local filesystem and returns its path.
* The $number_of_writes and $bytes_per_write parameters can be used to
* write $number_of_writes * $bytes_per_write times the character 'a' to the
* temporary file. All files created using this method will be deleted from
* the filesystem on tearDown(), i.e. after each test method was run.
*
* @param int $number_of_writes
* @param int $bytes_per_write
*
* @return string
*/
protected function createTempFile($number_of_writes = 0, $bytes_per_write = 0)
{
$filename = tempnam(sys_get_temp_dir(), 'phpseclib-test-');
$this->assertTrue(file_exists($filename));
$this->tempFilesToUnlinkOnTearDown[] = $filename;
if ($number_of_writes > 0 && $bytes_per_write > 0) {
$fp = fopen($filename, 'wb');
for ($i = 0; $i < $number_of_writes; ++$i) {
fwrite($fp, str_repeat('a', $bytes_per_write));
}
fclose($fp);
$this->assertSame($number_of_writes * $bytes_per_write, filesize($filename));
}
return $filename;
}
/**
* @param string $constant
* @param mixed $expected

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXII Andreas Fischer
* @copyright 2012 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXII Andreas Fischer
* @copyright 2012 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXIII Jim Wigginton
* @copyright 2013 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -0,0 +1,53 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
class Unit_Crypt_RandomTest extends PhpseclibTestCase
{
public function stringLengthData()
{
return array_map(array($this, 'wrap'), array(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 17, 19, 20, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 111, 128, 1000,
1024, 10000, 12345, 100000, 123456
));
}
/** @dataProvider stringLengthData */
public function testStringLength($length)
{
$this->assertSame(
$length,
strlen(crypt_random_string($length)),
'Failed asserting that a string of expected length was generated.'
);
}
/**
* Takes a set of random values of length 128 bits and asserts all taken
* values are unique.
*/
public function testStringUniqueness()
{
$values = array();
for ($i = 0; $i < 10000; ++$i) {
$rand = crypt_random_string(16);
$this->assertSame(16, strlen($rand));
$this->assertArrayNotHasKey(
$rand,
$values,
'Failed asserting that generated value does not exist in set.'
);
$values[$rand] = true;
}
}
protected function wrap($x)
{
// array() is not a function, but $this->wrap() is.
return array($x);
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXIV Jim Wigginton
* @copyright 2014 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMXIV Jim Wigginton
* @copyright 2014 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @copyright 2013 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXII Andreas Fischer
* @copyright 2012 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* @author Marc Scholten <marc@pedigital.de>
* @copyright MMXIII Marc Scholten
* @copyright 2013 Marc Scholten
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -2,7 +2,7 @@
/**
* @author Marc Scholten <marc@pedigital.de>
* @copyright MMXIII Marc Scholten
* @copyright 2013 Marc Scholten
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

View File

@ -13,5 +13,19 @@ set -x
USERNAME='phpseclib'
PASSWORD='EePoov8po1aethu2kied1ne0'
# Create phpseclib user and home directory
sudo useradd --create-home --base-dir /home "$USERNAME"
# Set phpseclib user password
echo "$USERNAME:$PASSWORD" | sudo chpasswd
# Create a 1024 bit RSA SSH key pair without passphrase for the travis user
ssh-keygen -t rsa -b 1024 -f "$HOME/.ssh/id_rsa" -q -N ""
# Add the generated private key to SSH agent of travis user
ssh-add "$HOME/.ssh/id_rsa"
# Allow the private key of the travis user to log in as phpseclib user
sudo mkdir -p "/home/$USERNAME/.ssh/"
sudo cp "$HOME/.ssh/id_rsa.pub" "/home/$USERNAME/.ssh/authorized_keys"
sudo chown "$USERNAME:$USERNAME" "/home/$USERNAME/.ssh/" -R