Skip to content

Commit

Permalink
Merge pull request #62 from kraken-php/ticket-56
Browse files Browse the repository at this point in the history
Feature #56 : Implemented async SSH driver
  • Loading branch information
khelle authored Apr 30, 2017
2 parents ed75d5a + 70ee2b2 commit d683f4d
Show file tree
Hide file tree
Showing 48 changed files with 4,575 additions and 603 deletions.
Empty file added .noninteractive
Empty file.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ php:
- 7.0
- 7.1

sudo: false

install:
before_script:
- sudo apt-get update -qq
- sudo apt-get install -y -qq libssh2-1-dev libssh2-php
- pecl install -f ssh2-beta < .noninteractive
- composer self-update
- composer install --no-interaction --prefer-source
- echo `whoami`":1234" | sudo chpasswd

script:
- vendor/bin/phpunit -d memory_limit=1024M --coverage-text
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
"vlucas/phpdotenv": "^2.3"
},
"require-dev": {
"phpunit/phpunit": "4.8.*|5.2.*"
"phpunit/phpunit": "4.8.*|5.3.*"
},
"suggest": {
"ext-libevent": ">=0.1.0",
"ext-event": "~1.0",
"ext-libev": "*",
"ext-zmq": "*",
"ext-fileinfo": "*"
"ext-fileinfo": "*",
"ext-ssh2": "*"
},
"replace": {
"kraken-php/channel": "self.version",
Expand All @@ -53,6 +54,7 @@
"kraken-php/promise": "self.version",
"kraken-php/root": "self.version",
"kraken-php/runtime": "self.version",
"kraken-php/ssh": "self.version",
"kraken-php/stream": "self.version",
"kraken-php/supervision": "self.version",
"kraken-php/test": "self.version",
Expand Down
10 changes: 3 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
verbose="true">

<testsuites>
<testsuite name="Kraken Unit Tests">
<directory suffix="Test.php">test/_Unit</directory>
</testsuite>

<testsuite name="Kraken Module Tests">
<testsuite name="Kraken Module">
<directory suffix="Test.php">test/_Module</directory>
</testsuite>

<testsuite name="Kraken Integration Tests">
<directory suffix="Test.php">test/_Integration</directory>
<testsuite name="Kraken Unit">
<directory suffix="Test.php">test/_Unit</directory>
</testsuite>
</testsuites>

Expand Down
11 changes: 11 additions & 0 deletions src/Event/BaseEventEmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,15 @@ protected function attachTimesListener($pointer, $event, $limit, callable $liste
return call_user_func_array($listener, func_get_args());
};
}

/**
* Destruct method.
*/
private function destructEventEmitterTrait()
{
$this->emitterBlocked = EventEmitter::EVENTS_FORWARD;
$this->eventPointers = [];
$this->eventListeners = [];
$this->forwardListeners = [];
}
}
2 changes: 1 addition & 1 deletion src/Event/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getHandler()
*/
public function getListener()
{
return $this->listener;
return isset($this->listener) ? $this->listener : function() {};
}

/**
Expand Down
38 changes: 38 additions & 0 deletions src/SSH/Auth/SSH2Agent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Agent based SSH2 authentication
*/
class SSH2Agent implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* Constructor
*
* @param string $username The authentication username
*/
public function __construct($username)
{
$this->username = $username;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_agent(
$conn,
$this->username
);
}
}
76 changes: 76 additions & 0 deletions src/SSH/Auth/SSH2HostBasedFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Host based SSH2 authentication.
*/
class SSH2HostBasedFile implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @var string
*/
protected $hostname;

/**
* @var string
*/
protected $publicKeyFile;

/**
* @var string
*/
protected $privateKeyFile;

/**
* @var null|string
*/
protected $passPhrase;

/**
* @var null|string
*/
protected $localUsername;

/**
* @param string $username The authentication username
* @param string $hostname The authentication hostname
* @param string $publicKeyFile The path of the public key file
* @param string $privateKeyFile The path of the private key file
* @param string $passPhrase An optional pass phrase for the key
* @param string $localUsername An optional local usernale. If omitted, the username will be used
*/
public function __construct($username, $hostname, $publicKeyFile, $privateKeyFile, $passPhrase = null, $localUsername = null)
{
$this->username = $username;
$this->hostname = $hostname;
$this->publicKeyFile = $publicKeyFile;
$this->privateKeyFile = $privateKeyFile;
$this->passPhrase = $passPhrase;
$this->localUsername = $localUsername;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_hostbased_file(
$conn,
$this->username,
$this->hostname,
$this->publicKeyFile,
$this->privateKeyFile,
$this->passPhrase,
$this->localUsername
);
}
}
33 changes: 33 additions & 0 deletions src/SSH/Auth/SSH2None.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Username based SSH2 authentication.
*/
class SSH2None implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @param string $username The authentication username
*/
public function __construct($username)
{
$this->username = $username;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return true === @ssh2_auth_none($conn, $this->username);
}
}
40 changes: 40 additions & 0 deletions src/SSH/Auth/SSH2Password.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Password based SSH2 authentication
*/
class SSH2Password implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @var string
*/
protected $password;

/**
* @param string $username The authentication username
* @param string $password The authentication password
*/
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_password($conn, $this->username, $this->password);
}
}
60 changes: 60 additions & 0 deletions src/SSH/Auth/SSH2PublicKeyFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Public key based SSH2 authentication
*/
class SSH2PublicKeyFile implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @var string
*/
protected $publicKeyFile;

/**
* @var string
*/
protected $privateKeyFile;

/**
* @var null|string
*/
protected $passPhrase;

/**
* @param string $username The authentication username
* @param string $publicKeyFile The path of the public key file
* @param string $privateKeyFile The path of the private key file
* @param string|null $passPhrase An optional pass phrase for the key
*/
public function __construct($username, $publicKeyFile, $privateKeyFile, $passPhrase = null)
{
$this->username = $username;
$this->publicKeyFile = $publicKeyFile;
$this->privateKeyFile = $privateKeyFile;
$this->passPhrase = $passPhrase;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_pubkey_file(
$conn,
$this->username,
$this->publicKeyFile,
$this->privateKeyFile,
$this->passPhrase
);
}
}
Loading

0 comments on commit d683f4d

Please sign in to comment.